summaryrefslogtreecommitdiffstatshomepage
path: root/tests/float/math_constants_extra.py
diff options
context:
space:
mode:
authorYoctopuce dev <dev@yoctopuce.com>2025-06-19 15:47:13 +0200
committerDamien George <damien@micropython.org>2025-06-24 00:30:08 +1000
commite57aa7e70a326659529d02891abb9a57b055fc0c (patch)
tree699f53a51d4defd79c0f16bad3b231cc515f0b36 /tests/float/math_constants_extra.py
parent66c01480226aaf880a9d6e88340772bd53bc0421 (diff)
downloadmicropython-e57aa7e70a326659529d02891abb9a57b055fc0c.tar.gz
micropython-e57aa7e70a326659529d02891abb9a57b055fc0c.zip
py/obj: Fix nan handling in object REPR_C and REPR_D.HEADmaster
CPython math.nan is positive with regards to copysign. The signaling bit (aka sign flag) was incorrectly set. In addition, REPR_C and REPR_D should only use the _true_ nan to prevent system crash in case of hand-crafted floats. For instance, with REPR_C, any nan-like float following the pattern `01111111 1xxxxxxx xxxxxxxx xxxxx1xx` would be switched to an immediate object or a qstr string. When the qstr index is too large, this would cause a crash. This commit fixes the issue, and adds the relevant test cases. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
Diffstat (limited to 'tests/float/math_constants_extra.py')
-rw-r--r--tests/float/math_constants_extra.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/tests/float/math_constants_extra.py b/tests/float/math_constants_extra.py
index dea49aef5a..756cb45803 100644
--- a/tests/float/math_constants_extra.py
+++ b/tests/float/math_constants_extra.py
@@ -9,9 +9,12 @@ except (ImportError, AttributeError):
raise SystemExit
print(math.tau == 2.0 * math.pi)
+print(math.copysign(1.0, math.tau))
print(math.inf == float("inf"))
print(-math.inf == -float("inf"))
+print(math.copysign(1.0, math.inf))
print(isnan(math.nan))
print(isnan(-math.nan))
+print(math.copysign(1.0, math.nan))