Message227277
| Author |
belopolsky |
| Recipients |
Arfrever, alex, belopolsky, casevh, pitrou, rhettinger, skrah, tim.peters |
| Date |
2014年09月22日.15:39:42 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1411400383.0.0.110517193167.issue22444@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
[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 |
|