From 62805873201d12c2a4fbb7ac89115a387b67b5bf Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 22 Mar 2014 20:44:15 +0000 Subject: [PATCH] py: Fix types in new math functions. --- py/builtinmath.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/py/builtinmath.c b/py/builtinmath.c index 818ac1d9dd..fa6a99f762 100644 --- a/py/builtinmath.c +++ b/py/builtinmath.c @@ -62,38 +62,37 @@ MATH_FUN_1(lgamma, lgamma) //TODO: factorial, fsum // Functions that return a tuple -mp_obj_t mp_math_frexp(mp_obj_t x_obj){ - machine_int_t int_exponent = 0; - mp_float_t significand = frexp(mp_obj_get_float(x_obj), &int_exponent); - mp_obj_t tuple[2]; - tuple[0] = mp_obj_new_float(significand); - tuple[1] = mp_obj_new_int(int_exponent); - return mp_obj_new_tuple(2, tuple); +mp_obj_t mp_math_frexp(mp_obj_t x_obj) { + int int_exponent = 0; + mp_float_t significand = MICROPY_FLOAT_C_FUN(frexp)(mp_obj_get_float(x_obj), &int_exponent); + mp_obj_t tuple[2]; + tuple[0] = mp_obj_new_float(significand); + tuple[1] = mp_obj_new_int(int_exponent); + return mp_obj_new_tuple(2, tuple); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_frexp_obj, mp_math_frexp); -mp_obj_t mp_math_modf(mp_obj_t x_obj){ - mp_float_t int_part = 0.0; - mp_float_t fractional_part = modf(mp_obj_get_float(x_obj), &int_part); - mp_obj_t tuple[2]; - tuple[0] = mp_obj_new_float(fractional_part); - tuple[1] = mp_obj_new_float(int_part); - return mp_obj_new_tuple(2, tuple); +mp_obj_t mp_math_modf(mp_obj_t x_obj) { + mp_float_t int_part = 0.0; + mp_float_t fractional_part = MICROPY_FLOAT_C_FUN(modf)(mp_obj_get_float(x_obj), &int_part); + mp_obj_t tuple[2]; + tuple[0] = mp_obj_new_float(fractional_part); + tuple[1] = mp_obj_new_float(int_part); + return mp_obj_new_tuple(2, tuple); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_modf_obj, mp_math_modf); // Angular conversions -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); +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); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_radians_obj, mp_math_radians); -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); +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); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees); - STATIC const mp_map_elem_t mp_module_math_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_math) }, { MP_OBJ_NEW_QSTR(MP_QSTR_e), (mp_obj_t)&mp_math_e_obj },