[issue47031] math.nan should note that NANs do not compare equal to anything
Steven D'Aprano
report at bugs.python.org
Thu Mar 24 06:42:44 EDT 2022
Steven D'Aprano <steve+python at pearwood.info> added the comment:
> We cannot guarantee that NAN never equal to anything, because we can
> create an object equal to it. For example mock.ANY
Sure. I don't expect that mock.ANY or other weird objects should obey
the IEEE-754 rules. But we're talking numeric comparisons here, not
arbitrary objects which may do arbitrary things in their `__eq__`
method.
The documentation for the math module assumes we're talking about
sensible, standard numeric values that don't play strange tricks on the
caller. Look at the first function documented:
math.ceil(x)
Return the ceiling of x, the smallest integer greater than or equal to
x. If x is not a float, delegates to x.__ceil__(), which should return
an Integral value.
class MyWeirdFloat(float):
def __ceil__(self):
return -1
math.ceil(MyWeirdFloat(25.9)) # Returns -1 instead of the ceiling.
Does the documentation really need to cover every imaginable weird
class? I don't think so. Let's keep it simple. NANs compared unequal
with all numeric values which directly or indirectly obey IEEE-754,
which includes floats.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue47031>
_______________________________________
More information about the Python-bugs-list
mailing list