|
@ -32,9 +32,8 @@ |
|
|
#include <math.h> |
|
|
#include <math.h> |
|
|
|
|
|
|
|
|
// M_PI is not part of the math.h standard and may not be defined
|
|
|
// M_PI is not part of the math.h standard and may not be defined
|
|
|
#ifndef M_PI |
|
|
// And by defining our own we can ensure it uses the correct const format.
|
|
|
#define M_PI (3.14159265358979323846) |
|
|
#define MP_PI MICROPY_FLOAT_CONST(3.14159265358979323846) |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
/// \module math - mathematical functions
|
|
|
/// \module math - mathematical functions
|
|
|
///
|
|
|
///
|
|
@ -204,13 +203,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_modf_obj, mp_math_modf); |
|
|
|
|
|
|
|
|
/// \function radians(x)
|
|
|
/// \function radians(x)
|
|
|
STATIC mp_obj_t mp_math_radians(mp_obj_t x_obj) { |
|
|
STATIC mp_obj_t mp_math_radians(mp_obj_t x_obj) { |
|
|
return mp_obj_new_float(mp_obj_get_float(x_obj) * M_PI / 180.0); |
|
|
return mp_obj_new_float(mp_obj_get_float(x_obj) * (MP_PI / MICROPY_FLOAT_CONST(180.0))); |
|
|
} |
|
|
} |
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_radians_obj, mp_math_radians); |
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_radians_obj, mp_math_radians); |
|
|
|
|
|
|
|
|
/// \function degrees(x)
|
|
|
/// \function degrees(x)
|
|
|
STATIC mp_obj_t mp_math_degrees(mp_obj_t x_obj) { |
|
|
STATIC mp_obj_t mp_math_degrees(mp_obj_t x_obj) { |
|
|
return mp_obj_new_float(mp_obj_get_float(x_obj) * 180.0 / M_PI); |
|
|
return mp_obj_new_float(mp_obj_get_float(x_obj) * (MICROPY_FLOAT_CONST(180.0) / MP_PI)); |
|
|
} |
|
|
} |
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees); |
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees); |
|
|
|
|
|
|
|
|