New submission from Pablo Acosta: The Greatest Common Divisor (gcd) algorithm sometimes breaks because the modulo operation does not always return a strict integer number, but one very, very close to one. This is enough to drive the algorithm astray from that point on.
Example: >> import fractions >> fractions.gcd(48, 18) >> 6 Which is corret, but: >> fractions.gcd(2.7, 107.3) >> 8.881784197001252e-16 when the answer should be 1. The fix seems simple, just cast the mod() operation in the algorithm: while b: a, b = b, int(a%b) return a ---------- components: Library (Lib) messages: 220221 nosy: pacosta priority: normal severity: normal status: open title: fractions.gcd failure type: behavior versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue21712> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com