[issue30933] Python not IEEE 754 float compliant for various zero operations

Mark Dickinson report at bugs.python.org
Fri Jul 14 15:20:08 EDT 2017


Mark Dickinson added the comment:

(-0) ** 0.5 is a power operation, not a square root operation. As such, the relevant part of IEEE 754-2008 is section 9.2.1, "Special values", which says:

> pow (±0, y) is +0 for finite y > 0 and not an odd integer

For the other cases, in general the philosophy is that we should raise exceptions where an FPE would be signalled, in preference to returning infinities and NaNs. So for example `math.sqrt(-1)` raises a ValueError rather than giving a NaN, and 1.0 / 0.0 raises ZeroDivisionError similarly. Unfortunately we don't have complete consistency here: for example 1e300 * 1e300 gives an infinity instead of raising. But that behaviour has been in the language for a looong time, and it's hard to change without breaking existing code.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30933>
_______________________________________


More information about the Python-bugs-list mailing list