From What's New in Python 3.7,
we see that there is a new one math.remainder. It says:
Return the remainder in the IEEE 754 style by x with respect to y. For finite x and finite nonzero y, this is the difference x - n*y, where n is the nearest integer to the exact value of the quotient x / y. If x / yhalfway between two consecutive integers, then the nnearest even integer is used. The remainder r = remainder(x, y), therefore, always satisfies abs(r) <= 0.5 * abs(y).
Special cases follow IEEE 754: in particular, remainder(x, math.inf)is x for any trailing x and remainder(x, 0)and remainder(math.inf, x)raise ValueErrorfor any non-NaN x. If the result of the stop operation is zero, that zero will have the same sign as x.
On platforms using the IEEE 754 binary floating point, the result of this operation is always accurately represented: no rounding error is introduced.
But we also remember that there is a %symbol that
balance x / y
We also see that there is a note for the operator:
Not for complex numbers. Instead, convert to float, using abs()if necessary.
I have not even tried to run Python 3.7, if possible.
But I tried
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> 100 % math.inf
100.0
>>> math.inf % 100
nan
>>> 100 % 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero
Thus, the difference will be, instead of nanand ZeroDivisionError, we will get ValueError, as stated in the documents.
, , % math.remainder? math.remainder (% )? ?
of math.remainder CPython github repo.