Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
6f495200
Commit
6f495200
authored
10 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Implement second arg for math.log (optional value for base).
parent
05c6fbca
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/modmath.c
+13
-2
13 additions, 2 deletions
py/modmath.c
tests/float/math_fun.py
+1
-0
1 addition, 0 deletions
tests/float/math_fun.py
with
14 additions
and
2 deletions
py/modmath.c
+
13
−
2
View file @
6f495200
...
@@ -68,8 +68,6 @@ MATH_FUN_2(pow, pow)
...
@@ -68,8 +68,6 @@ MATH_FUN_2(pow, pow)
MATH_FUN_1
(
exp
,
exp
)
MATH_FUN_1
(
exp
,
exp
)
/// \function expm1(x)
/// \function expm1(x)
MATH_FUN_1
(
expm1
,
expm1
)
MATH_FUN_1
(
expm1
,
expm1
)
/// \function log(x)
MATH_FUN_1
(
log
,
log
)
/// \function log2(x)
/// \function log2(x)
MATH_FUN_1
(
log2
,
log2
)
MATH_FUN_1
(
log2
,
log2
)
/// \function log10(x)
/// \function log10(x)
...
@@ -136,6 +134,19 @@ MATH_FUN_1(lgamma, lgamma)
...
@@ -136,6 +134,19 @@ MATH_FUN_1(lgamma, lgamma)
#endif
#endif
//TODO: factorial, fsum
//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
// Functions that return a tuple
/// \function frexp(x)
/// \function frexp(x)
...
...
This diff is collapsed.
Click to expand it.
tests/float/math_fun.py
+
1
−
0
View file @
6f495200
...
@@ -59,6 +59,7 @@ binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.)
...
@@ -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.
),)),
(
'
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.
),)),
(
'
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
),)),
(
'
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
:
for
function_name
,
function
,
test_vals
in
binary_functions
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment