Alexander Belopolsky added the comment:

[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

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22444>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to