[issue36028] Integer Division discrepancy with float

Raymond Hettinger report at bugs.python.org
Mon Feb 18 20:31:39 EST 2019


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

The open question in my mind is which is the least surprising definition of a//b.  Should it be math.floor(a/b) or divmod(a,b)[0]?

The advantage of the former is that floor(a/b) is arguably the definition of floor division. The advantage of the latter is that a//b, a%b, and divmod(a,b) are consistent with one another.

FWIW, it looks like NumPy and PyPy made the same design choice as CPython:

>>> a = numpy.array([4.0, 4.0, 4.0], dtype=numpy.float64)
>>> b = numpy.array([0.4, 0.5, 0.6], dtype=numpy.float64)
>>> a / b
array([10.        ,  8.        ,  6.66666667])
>>> a // b
array([9., 8., 6.])

$ pypy3
Python 3.5.3 (fdd60ed87e941677e8ea11acf9f1819466521bf2, Apr 26 2018, 01:25:35)
[PyPy 6.0.0 with GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>> 4.0 / 0.4
10.0
>>>> 4.0 // 0.4
9.0

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36028>
_______________________________________


More information about the Python-bugs-list mailing list