diff options
author | Colin Hogben <colin@infinnovation.co.uk> | 2016-05-09 22:11:34 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-05-12 13:28:45 +0100 |
commit | a896951a9a8d8585d094e5ee6d7d37ff17d1b73e (patch) | |
tree | 842129f36be9d86e0c198ffb03e6bf050a268c07 | |
parent | d45e5f8c357d13e66aeac644e2b5ead8c734025f (diff) |
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.
-rw-r--r-- | py/modmath.c | 5 | ||||
-rw-r--r-- | py/objfloat.c | 8 |
2 files changed, 13 insertions, 0 deletions
diff --git a/py/modmath.c b/py/modmath.c index 6abf8ab3e..54262f611 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 aa37f9ab2..85b8b1386 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; |