circuitpython/tests/float/math_constants_extra.py
Yoctopuce dev e57aa7e70a py/obj: Fix nan handling in object REPR_C and REPR_D.
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>
2025-06-24 00:30:08 +10:00

20 lines
480 B
Python

# Tests constants of the math module available only with MICROPY_PY_MATH_CONSTANTS.
try:
import math
from math import isnan
math.tau
except (ImportError, AttributeError):
print("SKIP")
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))