diff --git a/py/modmath.c b/py/modmath.c
index ec74e974e890b88297e18e5dafe7f33d739e279c..48ba4705823705e9448c6b9e64b9a979be24d926 100644
--- a/py/modmath.c
+++ b/py/modmath.c
@@ -52,6 +52,11 @@
     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); } \
     STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
 
+#if MP_NEED_LOG2
+// 1.442695040888963407354163704 is 1/_M_LN2
+#define log2(x) (log(x) * 1.442695040888963407354163704)
+#endif
+
 /// \function sqrt(x)
 /// Returns the square root of `x`.
 MATH_FUN_1(sqrt, sqrt)
diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h
index 0e1fb6a401d58a6f81957effebb2f892bd3091a5..4dbb8ee2e37af40cce62f3e64b6aa5e2d5546880 100644
--- a/unix/mpconfigport.h
+++ b/unix/mpconfigport.h
@@ -204,8 +204,7 @@ void mp_unix_mark_exec(void);
 #include <android/api-level.h>
 #if __ANDROID_API__ < 4
 // Bionic libc in Android 1.5 misses these 2 functions
-// 1.442695040888963407354163704 is 1/_M_LN2
-#define log2(x) (log(x) * 1.442695040888963407354163704)
+#define MP_NEED_LOG2 (1)
 #define nan(x) NAN
 #endif
 #endif