Mark Dickinson added the comment:
The only issue with subnormals is that a simple relative error test is
usually inappropriate. For example, on an IEEE 754 machine 2**-1073
should almost always be considered a good approximation to 2**-1074, since
the two floats are adjacent; but the relativ
D Hardy added the comment:
Oh; OK, thanks for the response.
Sorry, I've used +/- inf and NaN values in other languages and was under the
impression inf != inf under IEEE 754. I think this requires explicitly testing
for
infinity then.
For anyone interested, I've written a test which seems to
Mark Dickinson added the comment:
Section 5.11 of IEEE 754-2008, paragraph 2, says:
"""Infinite operands of the same sign shall compare equal."""
So Python's behaviour follows the standard here.
Producing 'is close to' tests is always tricky if you want to be able to
deal with IEEE special va
Tim Peters added the comment:
+inf == +inf, and -inf == -inf, are required by the 754 standard.
However, +inf - +inf, and -inf - -inf, are required (by the same
standard) to signal invalid operation and, if that signal is masked (as
it is in Python), to return a NaN. Then NaN == x is false for
New submission from D Hardy :
Currently python evaluates infinity as equal to itself in my tests (2.6.2 and
3.0.1+
from ubuntu). I'm not entirely sure whether the behaviour of 'inf == inf' is
specified
by IEEE 754, but it leads to results like:
>>> 1e400
inf
>>> 1e400 == 1e500
True
And hence