aboutsummaryrefslogtreecommitdiff
path: root/py/modmath.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-10-04 21:46:38 +1100
committerDamien George <damien.p.george@gmail.com>2017-10-10 16:01:04 +1100
commitd8d4e4dfbe4ca76a1b0adf4f1938562a308c6d48 (patch)
treef8a1128dabdcd955c791ed05637bbdf15947e971 /py/modmath.c
parent25e140652b946e9a136a16a9831c0b18f1285702 (diff)
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.
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 6c248844d..7eda7594d 100644
--- a/py/modmath.c
+++ b/py/modmath.c
@@ -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
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_## py_name ## _obj, mp_math_ ## py_name);
#if MP_NEED_LOG2
+#undef log2
+#undef log2f
// 1.442695040888963407354163704 is 1/_M_LN2
-#define log2(x) (log(x) * 1.442695040888963407354163704)
+mp_float_t MICROPY_FLOAT_C_FUN(log2)(mp_float_t x) {
+ return MICROPY_FLOAT_C_FUN(log)(x) * MICROPY_FLOAT_CONST(1.442695040888963407354163704);
+}
#endif
// sqrt(x): returns the square root of x