summaryrefslogtreecommitdiff
path: root/py/modmath.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2025-10-01 12:21:27 +1000
committerDamien George <damien@micropython.org>2025-10-01 23:59:15 +1000
commitdcbda765d1dc654cdcba06e0a01649256330794e (patch)
treebb540d2031bfe305a8a6ce70a5e38f02135871e1 /py/modmath.c
parent381cd730c834a1d071e7e90787ef7354b8532142 (diff)
py/modmath: Make MICROPY_PY_MATH_POW_FIX_NAN also fix pow(x, NaN) cases.
This is needed by the zephyr port. Combining it with the existing `MICROPY_PY_MATH_POW_FIX_NAN` option should be safe, and eliminates the need for a separate option. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/modmath.c')
-rw-r--r--py/modmath.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/py/modmath.c b/py/modmath.c
index 919a8ccd9..045c84215 100644
--- a/py/modmath.c
+++ b/py/modmath.c
@@ -99,12 +99,16 @@ mp_float_t MICROPY_FLOAT_C_FUN(log2)(mp_float_t x) {
MATH_FUN_1(sqrt, sqrt)
// pow(x, y): returns x to the power of y
#if MICROPY_PY_MATH_POW_FIX_NAN
-mp_float_t pow_func(mp_float_t x, mp_float_t y) {
+mp_float_t MICROPY_FLOAT_C_FUN(pow_func)(mp_float_t x, mp_float_t y) {
// pow(base, 0) returns 1 for any base, even when base is NaN
// pow(+1, exponent) returns 1 for any exponent, even when exponent is NaN
if (x == MICROPY_FLOAT_CONST(1.0) || y == MICROPY_FLOAT_CONST(0.0)) {
return MICROPY_FLOAT_CONST(1.0);
}
+ // pow(base, NaN) returns NaN for any other value of base
+ if (isnan(y)) {
+ return y;
+ }
return MICROPY_FLOAT_C_FUN(pow)(x, y);
}
MATH_FUN_2(pow, pow_func)