py/obj: Fix comparison of float/complex NaN with itself.

IEEE floating point is specified such that a comparison of NaN with itself
returns false, and Python respects these semantics.  This patch makes uPy
also have these semantics.  The fix has a minor impact on the speed of the
object-equality fast-path, but that seems to be unavoidable and it's much
more important to have correct behaviour (especially in this case where
the wrong answer for nan==nan is silently returned).
This commit is contained in:
Damien George
2017-09-04 14:16:27 +10:00
parent 9950865c39
commit d4b75f6b68
3 changed files with 20 additions and 1 deletions

View File

@@ -60,6 +60,11 @@ print(1.2 <= -3.4)
print(1.2 >= 3.4)
print(1.2 >= -3.4)
# comparison of nan is special
nan = float('nan')
print(nan == 1.2)
print(nan == nan)
try:
1.0 / 0
except ZeroDivisionError: