[issue32543] odd floor division behavior

2018-01-12 Thread Tim Peters
Tim Peters added the comment: This report appears to be the same: https://bugs.python.org/issue27463 One other thing to note: the Python docs are sometimes unclear about whether expressions are intended to be interpreted as Python code or as mathematical expressions. In: """ floor divisio

[issue32543] odd floor division behavior

2018-01-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: This is the result of multiple roundings. 0.9 and 0.1 can't be represented exactly as floats. They are approximated by binary fractions. >>> from fractions import Fraction >>> Fraction(0.9) Fraction(8106479329266893, 9007199254740992) >>> Fraction(0.1) Frac

[issue32543] odd floor division behavior

2018-01-12 Thread Ammar Askar
Ammar Askar added the comment: Looks like floor division for floats call into the divmod function, which has the same behavior: >>> 0.9 .__divmod__(0.1) (8.0, 0.09998) -- nosy: +ammar2 ___ Python tracker

[issue32543] odd floor division behavior

2018-01-12 Thread Steven D'Aprano
Steven D'Aprano added the comment: That does look at first glance like a bug in // to me. 0.9/0.1 is correctly rounded to 9.0 exactly, so flooring it should return 9 (as it does): # Python 3.5 on Linux py> 0.9/0.1 == 9 True py> math.floor(0.9/0.1) 9 So I too would expect that 0.9//0.1 should

[issue32543] odd floor division behavior

2018-01-12 Thread Nathan Goldbaum
New submission from Nathan Goldbaum : According to PEP 238: "floor division will be implemented in all the Python numeric types, and will have the semantics of: a // b == floor(a/b) except that the result type will be the common type into which a and b are coerced before the operation." Bu