py: Fix handling of NaN in certain pow implementations.

Adds a new compile-time option MICROPY_PY_MATH_POW_FIX_NAN for use with
toolchains that don't handle pow-of-NaN correctly.
This commit is contained in:
stijn
2020-09-08 15:22:34 +02:00
committed by Damien George
parent 8d5a40c86e
commit 2e54d9d146
5 changed files with 26 additions and 1 deletions

View File

@@ -300,6 +300,12 @@ mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t
mp_raise_ValueError(MP_ERROR_TEXT("complex values not supported"));
#endif
}
#if MICROPY_PY_MATH_POW_FIX_NAN // Also see modmath.c.
if (lhs_val == MICROPY_FLOAT_CONST(1.0) || rhs_val == MICROPY_FLOAT_CONST(0.0)) {
lhs_val = MICROPY_FLOAT_CONST(1.0);
break;
}
#endif
lhs_val = MICROPY_FLOAT_C_FUN(pow)(lhs_val, rhs_val);
break;
case MP_BINARY_OP_DIVMOD: {