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) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log_obj, mp_cmath_log);
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
/// \function log10(z)
/// 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) {
......@@ -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));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log10_obj, mp_cmath_log10);
#endif
/// \function sqrt(z)
/// Return the square-root of `z`.
......@@ -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_exp), (mp_obj_t)&mp_cmath_exp_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 },
#endif
{ 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_asin), (mp_obj_t)&mp_cmath_asin_obj },
......
......@@ -68,7 +68,6 @@ MATH_FUN_1(exp, exp)
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
/// \function expm1(x)
MATH_FUN_1(expm1, expm1)
#endif
/// \function log2(x)
MATH_FUN_1(log2, log2)
/// \function log10(x)
......@@ -85,6 +84,7 @@ MATH_FUN_1(acosh, acosh)
MATH_FUN_1(asinh, asinh)
/// \function atanh(x)
MATH_FUN_1(atanh, atanh)
#endif
/// \function cos(x)
MATH_FUN_1(cos, cos)
/// \function sin(x)
......@@ -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 },
#endif
{ 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_log10), (mp_obj_t)&mp_math_log10_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[] = {
{ 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_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_sin), (mp_obj_t)&mp_math_sin_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_tan), (mp_obj_t)&mp_math_tan_obj },
......
......@@ -370,8 +370,11 @@ Q(pi)
Q(sqrt)
Q(pow)
Q(exp)
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
Q(expm1)
#endif
Q(log)
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
Q(log2)
Q(log10)
Q(cosh)
......@@ -380,6 +383,7 @@ Q(tanh)
Q(acosh)
Q(asinh)
Q(atanh)
#endif
Q(cos)
Q(sin)
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