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
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
6b8b56f8
Commit
6b8b56f8
authored
7 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py/modmath: Check for zero division in log with 2 args.
parent
9ed5e80e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/modmath.c
+2
-0
2 additions, 0 deletions
py/modmath.c
tests/float/math_fun.py
+3
-3
3 additions, 3 deletions
tests/float/math_fun.py
with
5 additions
and
3 deletions
py/modmath.c
+
2
−
0
View file @
6b8b56f8
...
...
@@ -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
));
}
...
...
This diff is collapsed.
Click to expand it.
tests/float/math_fun.py
+
3
−
3
View file @
6b8b56f8
...
...
@@ -51,7 +51,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.
),
(
0.
,
1.
),
(
1.
,
0.
),
(
-
1.
,
1.
),
(
1.
,
-
1.
))),
(
'
log
'
,
log
,
((
2.
,
2.
),
(
3.
,
2.
),
(
4.
,
5.
),
(
0.
,
1.
),
(
1.
,
0.
),
(
-
1.
,
1.
),
(
1.
,
-
1.
),
(
2.
,
1.
))),
]
for
function_name
,
function
,
test_vals
in
binary_functions
:
...
...
@@ -59,5 +59,5 @@ for function_name, function, test_vals in binary_functions:
for
value1
,
value2
in
test_vals
:
try
:
print
(
"
{:.5g}
"
.
format
(
function
(
value1
,
value2
)))
except
ValueError
as
e
:
print
(
str
(
e
))
except
(
ValueError
,
ZeroDivisionError
)
as
e
:
print
(
type
(
e
))
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