[issue21712] fractions.gcd failure

2014-06-11 Thread Tim Peters
Tim Peters added the comment: @pacosta, if Mark's answer is too abstract, here's a complete session showing that the result you got for gcd(2.7, 107.3) is in fact exactly correct: >>> import fractions >>> f1 = fractions.Fraction(2.7) >>> f2 = fractions.Fraction(107.3) >>> f1 Fraction(3039929748

[issue21712] fractions.gcd failure

2014-06-11 Thread Pablo Acosta
Pablo Acosta added the comment: Understood and agreed. My bad too for not reading the documentation more carefully. Thank you for the detailed explanation. Pablo > On Jun 11, 2014, at 2:52 PM, Tim Peters wrote: > > > Tim Peters added the comment: > > @pacosta, if Mark's answer is too abstr

[issue21712] fractions.gcd failure

2014-06-11 Thread Mark Dickinson
Mark Dickinson added the comment: Agreed with Tim. Oddly enough[1], remembering that with binary floating-point numbers, what you see is not what you get[2], it turns out that 8.881784197001252e-16 (= Fraction(1, 1125899906842624)) is in fact *exactly* the right answer, in that it's a generat

[issue21712] fractions.gcd failure

2014-06-10 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- resolution: -> wont fix status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing

[issue21712] fractions.gcd failure

2014-06-10 Thread Tim Peters
Tim Peters added the comment: The gcd function is documented as taking two integer arguments: "Return the greatest common divisor of the integers a and b." I'm -0 on generalizing it, and also -0 on burning cycles to enforce the restriction to integer arguments. It's just silly ;-) --

[issue21712] fractions.gcd failure

2014-06-10 Thread Ned Deily
Changes by Ned Deily : -- nosy: +mark.dickinson, rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: htt

[issue21712] fractions.gcd failure

2014-06-10 Thread Pablo Acosta
Pablo Acosta added the comment: I will correct myself one more time (hopefully the last): while b: a, b = b, round(a % b, 10) return a a b fractions.gcd proposed_algorithm -- 48

[issue21712] fractions.gcd failure

2014-06-10 Thread Pablo Acosta
Pablo Acosta added the comment: Actually probably int(round(a%b)) would be better. -- ___ Python tracker ___ ___ Python-bugs-list mail

[issue21712] fractions.gcd failure

2014-06-10 Thread Pablo Acosta
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 frac