py: Implement second arg for math.log (optional value for base).
This commit is contained in:
parent
05c6fbcae6
commit
6f49520042
15
py/modmath.c
15
py/modmath.c
@ -68,8 +68,6 @@ MATH_FUN_2(pow, pow)
|
||||
MATH_FUN_1(exp, exp)
|
||||
/// \function expm1(x)
|
||||
MATH_FUN_1(expm1, expm1)
|
||||
/// \function log(x)
|
||||
MATH_FUN_1(log, log)
|
||||
/// \function log2(x)
|
||||
MATH_FUN_1(log2, log2)
|
||||
/// \function log10(x)
|
||||
@ -136,6 +134,19 @@ MATH_FUN_1(lgamma, lgamma)
|
||||
#endif
|
||||
//TODO: factorial, fsum
|
||||
|
||||
// Function that takes a variable number of arguments
|
||||
|
||||
// log(x[, base])
|
||||
STATIC mp_obj_t mp_math_log(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
mp_float_t l = MICROPY_FLOAT_C_FUN(log)(mp_obj_get_float(args[0]));
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_float(l);
|
||||
} else {
|
||||
return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(mp_obj_get_float(args[1])));
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_math_log_obj, 1, 2, mp_math_log);
|
||||
|
||||
// Functions that return a tuple
|
||||
|
||||
/// \function frexp(x)
|
||||
|
@ -59,6 +59,7 @@ binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.)
|
||||
('atan2', atan2, ((1., 0.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)),
|
||||
('fmod', fmod, ((1., 1.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)),
|
||||
('ldexp', ldexp, ((1., 0), (0., 1), (2., 2), (3., -2), (-3., -4),)),
|
||||
('log', log, ((2., 2.), (3., 2.), (4., 5.))),
|
||||
]
|
||||
|
||||
for function_name, function, test_vals in binary_functions:
|
||||
|
Loading…
x
Reference in New Issue
Block a user