Skip to content

Commit d8d4e4d

Browse files
committed
py/modmath: Convert log2 macro into a function.
So that a pointer to it can be passed as a pointer to math_generic_1. This patch also makes the function work for single and double precision floating point.
1 parent 25e1406 commit d8d4e4d

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

py/modmath.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ STATIC mp_obj_t math_generic_2(mp_obj_t x_obj, mp_obj_t y_obj, mp_float_t (*f)(m
8585
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_## py_name ## _obj, mp_math_ ## py_name);
8686

8787
#if MP_NEED_LOG2
88+
#undef log2
89+
#undef log2f
8890
// 1.442695040888963407354163704 is 1/_M_LN2
89-
#define log2(x) (log(x) * 1.442695040888963407354163704)
91+
mp_float_t MICROPY_FLOAT_C_FUN(log2)(mp_float_t x) {
92+
return MICROPY_FLOAT_C_FUN(log)(x) * MICROPY_FLOAT_CONST(1.442695040888963407354163704);
93+
}
9094
#endif
9195

9296
// sqrt(x): returns the square root of x

0 commit comments

Comments
 (0)