diff --git a/py/modmath.c b/py/modmath.c
index 6abf8ab3e99d027b36690681aa2ba15f9f79fe7d..54262f6115f4c5a46991dd1e84b80b921bb396ea 100644
--- a/py/modmath.c
+++ b/py/modmath.c
@@ -31,6 +31,11 @@
 
 #include <math.h>
 
+// M_PI is not part of the math.h standard and may not be defined
+#ifndef M_PI
+#define M_PI (3.14159265358979323846)
+#endif
+
 /// \module math - mathematical functions
 ///
 /// The `math` module provides some basic mathematical funtions for
diff --git a/py/objfloat.c b/py/objfloat.c
index aa37f9ab2dd1f1d94aa0d3a584c866dadb839882..85b8b138610f26c40691548916cdd10435227c5c 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -41,6 +41,14 @@
 
 #if MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_C && MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_D
 
+// M_E and M_PI are not part of the math.h standard and may not be defined
+#ifndef M_E
+#define M_E (2.7182818284590452354)
+#endif
+#ifndef M_PI
+#define M_PI (3.14159265358979323846)
+#endif
+
 typedef struct _mp_obj_float_t {
     mp_obj_base_t base;
     mp_float_t value;