Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
6f495200
Commit
6f495200
authored
Jun 13, 2015
by
Damien George
Browse files
py: Implement second arg for math.log (optional value for base).
parent
05c6fbca
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/modmath.c
View file @
6f495200
...
...
@@ -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)
...
...
tests/float/math_fun.py
View file @
6f495200
...
...
@@ -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
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment