Message 335872 - Python tracker

Message335872

Author tim.peters
Recipients Au Vo, mark.dickinson, remi.lapeyre, rhettinger, skrah, tim.peters
Date 2019-02-18.22:46:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1550530001.56.0.77942594815.issue36028@roundup.psfhosted.org>
In-reply-to
Content
"Multiple roundings" in the float code is a red herring - that's just implementation details trying to cheaply get the same effect as computing with infinite precision.  Here with actual unbounded precision:

>>> from fractions import Fraction
>>> y = Fraction(0.4)
>>> y
Fraction(3602879701896397, 9007199254740992)
>>> q = 4 / y
>>> q
Fraction(36028797018963968, 3602879701896397)
>>> int(q)
9
>>> 4 - 9 * y
Fraction(3602879701896395, 9007199254740992)
>>> float(_)
0.3999999999999998
>>> 

So exactly the same results as divmod(4, 0.4) returned.

The underlying problem here is that the infinitely precise result of 4.0 / 0.4 is NOT an integer, in turn stemming from that the float 0.4 is not four tenths.

So I recommend to close this as not-a-bug, but I'm not doing that now because I want clarification on what the OP meant by saying the results differ between Pythons 2 and 3.  I see no differences here between Pythons 2.7.11 and 3.7.2 on 64-bit Windows (not in 4.0 vs 0.4, or in any of the other cases the OP mentioned).
History
Date User Action Args
2019-02-18 22:46:41tim.peterssetrecipients: + tim.peters, rhettinger, mark.dickinson, skrah, remi.lapeyre, Au Vo
2019-02-18 22:46:41tim.peterssetmessageid: <1550530001.56.0.77942594815.issue36028@roundup.psfhosted.org>
2019-02-18 22:46:41tim.peterslinkissue36028 messages
2019-02-18 22:46:41tim.peterscreate