Commit a24eafac authored by Damien George's avatar Damien George

py/modmath: Make log2, log10 and hyperbolic funcs be SPECIAL_FUNCTIONS.

Will be included only when MICROPY_PY_MATH_SPECIAL_FUNCTIONS is enabled.

Also covers cmath module (but only log10 is there at the moment).
parent 2c838942
...@@ -86,6 +86,7 @@ STATIC mp_obj_t mp_cmath_log(mp_obj_t z_obj) { ...@@ -86,6 +86,7 @@ STATIC mp_obj_t mp_cmath_log(mp_obj_t z_obj) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log_obj, mp_cmath_log); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log_obj, mp_cmath_log);
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
/// \function log10(z) /// \function log10(z)
/// Return the base-10 logarithm of `z`. The branch cut is along the negative real axis. /// Return the base-10 logarithm of `z`. The branch cut is along the negative real axis.
STATIC mp_obj_t mp_cmath_log10(mp_obj_t z_obj) { STATIC mp_obj_t mp_cmath_log10(mp_obj_t z_obj) {
...@@ -94,6 +95,7 @@ STATIC mp_obj_t mp_cmath_log10(mp_obj_t z_obj) { ...@@ -94,6 +95,7 @@ STATIC mp_obj_t mp_cmath_log10(mp_obj_t z_obj) {
return mp_obj_new_complex(0.5 * MICROPY_FLOAT_C_FUN(log10)(real*real + imag*imag), 0.4342944819032518 * MICROPY_FLOAT_C_FUN(atan2)(imag, real)); return mp_obj_new_complex(0.5 * MICROPY_FLOAT_C_FUN(log10)(real*real + imag*imag), 0.4342944819032518 * MICROPY_FLOAT_C_FUN(atan2)(imag, real));
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log10_obj, mp_cmath_log10); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log10_obj, mp_cmath_log10);
#endif
/// \function sqrt(z) /// \function sqrt(z)
/// Return the square-root of `z`. /// Return the square-root of `z`.
...@@ -133,7 +135,9 @@ STATIC const mp_map_elem_t mp_module_cmath_globals_table[] = { ...@@ -133,7 +135,9 @@ STATIC const mp_map_elem_t mp_module_cmath_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_rect), (mp_obj_t)&mp_cmath_rect_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_rect), (mp_obj_t)&mp_cmath_rect_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_exp), (mp_obj_t)&mp_cmath_exp_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_exp), (mp_obj_t)&mp_cmath_exp_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_log), (mp_obj_t)&mp_cmath_log_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_log), (mp_obj_t)&mp_cmath_log_obj },
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
{ MP_OBJ_NEW_QSTR(MP_QSTR_log10), (mp_obj_t)&mp_cmath_log10_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_log10), (mp_obj_t)&mp_cmath_log10_obj },
#endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_sqrt), (mp_obj_t)&mp_cmath_sqrt_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_sqrt), (mp_obj_t)&mp_cmath_sqrt_obj },
//{ MP_OBJ_NEW_QSTR(MP_QSTR_acos), (mp_obj_t)&mp_cmath_acos_obj }, //{ MP_OBJ_NEW_QSTR(MP_QSTR_acos), (mp_obj_t)&mp_cmath_acos_obj },
//{ MP_OBJ_NEW_QSTR(MP_QSTR_asin), (mp_obj_t)&mp_cmath_asin_obj }, //{ MP_OBJ_NEW_QSTR(MP_QSTR_asin), (mp_obj_t)&mp_cmath_asin_obj },
......
...@@ -68,7 +68,6 @@ MATH_FUN_1(exp, exp) ...@@ -68,7 +68,6 @@ MATH_FUN_1(exp, exp)
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS #if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
/// \function expm1(x) /// \function expm1(x)
MATH_FUN_1(expm1, expm1) MATH_FUN_1(expm1, expm1)
#endif
/// \function log2(x) /// \function log2(x)
MATH_FUN_1(log2, log2) MATH_FUN_1(log2, log2)
/// \function log10(x) /// \function log10(x)
...@@ -85,6 +84,7 @@ MATH_FUN_1(acosh, acosh) ...@@ -85,6 +84,7 @@ MATH_FUN_1(acosh, acosh)
MATH_FUN_1(asinh, asinh) MATH_FUN_1(asinh, asinh)
/// \function atanh(x) /// \function atanh(x)
MATH_FUN_1(atanh, atanh) MATH_FUN_1(atanh, atanh)
#endif
/// \function cos(x) /// \function cos(x)
MATH_FUN_1(cos, cos) MATH_FUN_1(cos, cos)
/// \function sin(x) /// \function sin(x)
...@@ -198,6 +198,7 @@ STATIC const mp_map_elem_t mp_module_math_globals_table[] = { ...@@ -198,6 +198,7 @@ STATIC const mp_map_elem_t mp_module_math_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_expm1), (mp_obj_t)&mp_math_expm1_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_expm1), (mp_obj_t)&mp_math_expm1_obj },
#endif #endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_log), (mp_obj_t)&mp_math_log_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_log), (mp_obj_t)&mp_math_log_obj },
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
{ MP_OBJ_NEW_QSTR(MP_QSTR_log2), (mp_obj_t)&mp_math_log2_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_log2), (mp_obj_t)&mp_math_log2_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_log10), (mp_obj_t)&mp_math_log10_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_log10), (mp_obj_t)&mp_math_log10_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_cosh), (mp_obj_t)&mp_math_cosh_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_cosh), (mp_obj_t)&mp_math_cosh_obj },
...@@ -206,6 +207,7 @@ STATIC const mp_map_elem_t mp_module_math_globals_table[] = { ...@@ -206,6 +207,7 @@ STATIC const mp_map_elem_t mp_module_math_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_acosh), (mp_obj_t)&mp_math_acosh_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_acosh), (mp_obj_t)&mp_math_acosh_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_asinh), (mp_obj_t)&mp_math_asinh_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_asinh), (mp_obj_t)&mp_math_asinh_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_atanh), (mp_obj_t)&mp_math_atanh_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_atanh), (mp_obj_t)&mp_math_atanh_obj },
#endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_cos), (mp_obj_t)&mp_math_cos_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_cos), (mp_obj_t)&mp_math_cos_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_sin), (mp_obj_t)&mp_math_sin_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_sin), (mp_obj_t)&mp_math_sin_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_tan), (mp_obj_t)&mp_math_tan_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_tan), (mp_obj_t)&mp_math_tan_obj },
......
...@@ -370,8 +370,11 @@ Q(pi) ...@@ -370,8 +370,11 @@ Q(pi)
Q(sqrt) Q(sqrt)
Q(pow) Q(pow)
Q(exp) Q(exp)
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
Q(expm1) Q(expm1)
#endif
Q(log) Q(log)
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
Q(log2) Q(log2)
Q(log10) Q(log10)
Q(cosh) Q(cosh)
...@@ -380,6 +383,7 @@ Q(tanh) ...@@ -380,6 +383,7 @@ Q(tanh)
Q(acosh) Q(acosh)
Q(asinh) Q(asinh)
Q(atanh) Q(atanh)
#endif
Q(cos) Q(cos)
Q(sin) Q(sin)
Q(tan) Q(tan)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment