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
9dcc60d0
Commit
9dcc60d0
authored
11 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Detect ZeroDivisionError properly for floats.
parent
212f89e6
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
py/objfloat.c
+9
-6
9 additions, 6 deletions
py/objfloat.c
with
9 additions
and
6 deletions
py/objfloat.c
+
9
−
6
View file @
9dcc60d0
...
...
@@ -118,15 +118,18 @@ mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs_in) {
// TODO: verify that C floor matches Python semantics
case
MP_BINARY_OP_FLOOR_DIVIDE
:
case
MP_BINARY_OP_INPLACE_FLOOR_DIVIDE
:
if
(
rhs_val
==
0
)
{
zero_division_error:
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_ZeroDivisionError
,
"float division by zero"
));
}
lhs_val
=
MICROPY_FLOAT_C_FUN
(
floor
)(
lhs_val
/
rhs_val
);
goto
check_zero_division
;
break
;
case
MP_BINARY_OP_TRUE_DIVIDE
:
case
MP_BINARY_OP_INPLACE_TRUE_DIVIDE
:
lhs_val
/=
rhs_val
;
check_zero_division:
if
(
isinf
(
lhs_val
)){
// check for division by zero
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_ZeroDivisionError
,
"float division by zero"
));
if
(
rhs_val
==
0
)
{
goto
zero_division_error
;
}
lhs_val
/=
rhs_val
;
break
;
case
MP_BINARY_OP_POWER
:
case
MP_BINARY_OP_INPLACE_POWER
:
lhs_val
=
MICROPY_FLOAT_C_FUN
(
pow
)(
lhs_val
,
rhs_val
);
break
;
...
...
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