summaryrefslogtreecommitdiffstatshomepage
path: root/py/obj.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/obj.c')
-rw-r--r--py/obj.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/py/obj.c b/py/obj.c
index 90ce47e8fb..857fe373f2 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -162,7 +162,16 @@ bool mp_obj_is_callable(mp_obj_t o_in) {
// comparison returns NotImplemented, == and != are decided by comparing the object
// pointer."
bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
- if (o1 == o2) {
+ // Float (and complex) NaN is never equal to anything, not even itself,
+ // so we must have a special check here to cover those cases.
+ if (o1 == o2
+ #if MICROPY_PY_BUILTINS_FLOAT
+ && !mp_obj_is_float(o1)
+ #endif
+ #if MICROPY_PY_BUILTINS_COMPLEX
+ && !MP_OBJ_IS_TYPE(o1, &mp_type_complex)
+ #endif
+ ) {
return true;
}
if (o1 == mp_const_none || o2 == mp_const_none) {