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
5589db88
Commit
5589db88
authored
11 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Implement complex division.
parent
e2835c16
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/objcomplex.c
+28
-10
28 additions, 10 deletions
py/objcomplex.c
with
28 additions
and
10 deletions
py/objcomplex.c
+
28
−
10
View file @
5589db88
...
...
@@ -144,22 +144,40 @@ mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_im
lhs_imag
-=
rhs_imag
;
break
;
case
MP_BINARY_OP_MULTIPLY
:
case
MP_BINARY_OP_INPLACE_MULTIPLY
:
{
mp_float_t
real
=
lhs_real
*
rhs_real
-
lhs_imag
*
rhs_imag
;
case
MP_BINARY_OP_INPLACE_MULTIPLY
:
{
mp_float_t
real
;
multiply:
real
=
lhs_real
*
rhs_real
-
lhs_imag
*
rhs_imag
;
lhs_imag
=
lhs_real
*
rhs_imag
+
lhs_imag
*
rhs_real
;
lhs_real
=
real
;
break
;
}
/* TODO floor(?) the value
case
MP_BINARY_OP_FLOOR_DIVIDE
:
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
val = lhs_val / rhs_val; break;
*/
/* TODO
case
MP_BINARY_OP_INPLACE_FLOOR_DIVIDE
:
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"can't do truncated division of a complex number"
));
case
MP_BINARY_OP_TRUE_DIVIDE
:
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE: val = lhs_val / rhs_val; break;
*/
return
NULL
;
// op not supported
case
MP_BINARY_OP_INPLACE_TRUE_DIVIDE
:
if
(
rhs_imag
==
0
)
{
if
(
rhs_real
==
0
)
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_ZeroDivisionError
,
"complex division by zero"
));
}
lhs_real
/=
rhs_real
;
lhs_imag
/=
rhs_real
;
}
else
if
(
rhs_real
==
0
)
{
mp_float_t
real
=
lhs_imag
/
rhs_imag
;
lhs_imag
=
-
lhs_real
/
rhs_imag
;
lhs_real
=
real
;
}
else
{
mp_float_t
rhs_len_sq
=
rhs_real
*
rhs_real
+
rhs_imag
*
rhs_imag
;
rhs_real
/=
rhs_len_sq
;
rhs_imag
/=
-
rhs_len_sq
;
goto
multiply
;
}
break
;
default:
return
MP_OBJ_NULL
;
// op not supported
}
return
mp_obj_new_complex
(
lhs_real
,
lhs_imag
);
}
...
...
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