Skip to content

Commit 6d1eabf

Browse files
committed
unix/mpconfigport: Move log2() definition to modmath.c.
It's safer to define it where it's used, defining it for all source files may lead to hard to diagnose conflicts in corner cases.
1 parent 432e827 commit 6d1eabf

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

py/modmath.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { mp_int_t x = MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj)); return mp_obj_new_int(x); } \
5353
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
5454

55+
#if MP_NEED_LOG2
56+
// 1.442695040888963407354163704 is 1/_M_LN2
57+
#define log2(x) (log(x) * 1.442695040888963407354163704)
58+
#endif
59+
5560
/// \function sqrt(x)
5661
/// Returns the square root of `x`.
5762
MATH_FUN_1(sqrt, sqrt)

unix/mpconfigport.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ void mp_unix_mark_exec(void);
204204
#include <android/api-level.h>
205205
#if __ANDROID_API__ < 4
206206
// Bionic libc in Android 1.5 misses these 2 functions
207-
// 1.442695040888963407354163704 is 1/_M_LN2
208-
#define log2(x) (log(x) * 1.442695040888963407354163704)
207+
#define MP_NEED_LOG2 (1)
209208
#define nan(x) NAN
210209
#endif
211210
#endif

0 commit comments

Comments
 (0)