py/modmath: Check for zero division in log with 2 args.

This commit is contained in:
Damien George
2017-07-04 02:15:11 +10:00
parent 9ed5e80eea
commit 6b8b56f859
2 changed files with 5 additions and 3 deletions

View File

@@ -168,6 +168,8 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) {
mp_float_t base = mp_obj_get_float(args[1]);
if (base <= (mp_float_t)0.0) {
math_error();
} else if (base == (mp_float_t)1.0) {
mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero");
}
return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base));
}