Unexpected results comparing float to Fraction

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Jul 29 13:27:10 EDT 2013


On Mon, 29 Jul 2013 17:48:21 +0100, MRAB wrote:

> On 29/07/2013 17:20, Chris Angelico wrote:
>> On Mon, Jul 29, 2013 at 5:09 PM, MRAB <python at mrabarnett.plus.com>
>> wrote:
>>> I'm surprised that Fraction(1/3) != Fraction(1, 3); after all, floats
>>> are approximate anyway, and the float value 1/3 is more likely to be
>>> Fraction(1, 3) than Fraction(6004799503160661, 18014398509481984).
>>
>> At what point should it become Fraction(1, 3)?
>>
> When the error drops below a certain threshold.

Good plan! I pick a threshold of 42.7. Anyone got a better threshold?

*wink*



-- 
Steven



More information about the Python-list mailing list