This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pacosta
Recipients pacosta
Date 2014-06-11.01:23:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1402449836.52.0.701887741943.issue21712@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2014-06-11 01:23:56pacostasetrecipients: + pacosta
2014-06-11 01:23:56pacostasetmessageid: <1402449836.52.0.701887741943.issue21712@psf.upfronthosting.co.za>
2014-06-11 01:23:56pacostalinkissue21712 messages
2014-06-11 01:23:55pacostacreate