Message227277
[Raymond]
> The current behavior has been around for a long time and is implemented in several modules including decimal and fractions.
No, in the fractions module floor division returns an int:
>>> type(Fraction(2) // Fraction(1))
<class 'int'>
It is also implemented in the datetime module where
>>> type(timedelta(2) // timedelta(1))
<class 'int'>
[Raymond]
# Here is a simple example of a chain of calculations
# where preserving the type matters
..
def f(x, y):
return x // 3 * 5 / 7 + y
def g(x, y):
return int(x // 3) * 5 / 7 + y
[/Raymond]
I am not sure what is the problem here. In Python 3:
>>> f(12.143, 0.667)
3.5241428571428575
>>> g(12.143, 0.667)
3.5241428571428575 |
|
Date |
User |
Action |
Args |
2014-09-22 15:39:43 | belopolsky | set | recipients:
+ belopolsky, tim.peters, rhettinger, pitrou, casevh, Arfrever, alex, skrah |
2014-09-22 15:39:43 | belopolsky | set | messageid: <1411400383.0.0.110517193167.issue22444@psf.upfronthosting.co.za> |
2014-09-22 15:39:42 | belopolsky | link | issue22444 messages |
2014-09-22 15:39:42 | belopolsky | create | |
|