Skip to content

Commit a896951

Browse files
Colin Hogbendpgeorge
authored andcommitted
py/objfloat, py/modmath: Ensure M_PI and M_E defined.
In some compliation enviroments (e.g. mbed online compiler) with strict standards compliance, <math.h> does not define constants such as M_PI. Provide fallback definitions of M_E and M_PI where needed.
1 parent d45e5f8 commit a896951

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

py/modmath.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131

3232
#include <math.h>
3333

34+
// M_PI is not part of the math.h standard and may not be defined
35+
#ifndef M_PI
36+
#define M_PI (3.14159265358979323846)
37+
#endif
38+
3439
/// \module math - mathematical functions
3540
///
3641
/// The `math` module provides some basic mathematical funtions for

py/objfloat.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141

4242
#if MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_C && MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_D
4343

44+
// M_E and M_PI are not part of the math.h standard and may not be defined
45+
#ifndef M_E
46+
#define M_E (2.7182818284590452354)
47+
#endif
48+
#ifndef M_PI
49+
#define M_PI (3.14159265358979323846)
50+
#endif
51+
4452
typedef struct _mp_obj_float_t {
4553
mp_obj_base_t base;
4654
mp_float_t value;

0 commit comments

Comments
 (0)