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
f20375ee
Commit
f20375ee
authored
10 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Add .real and .imag attributes to complex numbers.
parent
bb91f119
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/objcomplex.c
+10
-0
10 additions, 0 deletions
py/objcomplex.c
py/qstrdefs.h
+4
-0
4 additions, 0 deletions
py/qstrdefs.h
with
14 additions
and
0 deletions
py/objcomplex.c
+
10
−
0
View file @
f20375ee
...
...
@@ -132,6 +132,15 @@ STATIC mp_obj_t complex_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return
mp_obj_complex_binary_op
(
op
,
lhs
->
real
,
lhs
->
imag
,
rhs_in
);
}
STATIC
void
complex_load_attr
(
mp_obj_t
self_in
,
qstr
attr
,
mp_obj_t
*
dest
)
{
mp_obj_complex_t
*
self
=
self_in
;
if
(
attr
==
MP_QSTR_real
)
{
dest
[
0
]
=
mp_obj_new_float
(
self
->
real
);
}
else
if
(
attr
==
MP_QSTR_imag
)
{
dest
[
0
]
=
mp_obj_new_float
(
self
->
imag
);
}
}
const
mp_obj_type_t
mp_type_complex
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_complex
,
...
...
@@ -139,6 +148,7 @@ const mp_obj_type_t mp_type_complex = {
.
make_new
=
complex_make_new
,
.
unary_op
=
complex_unary_op
,
.
binary_op
=
complex_binary_op
,
.
load_attr
=
complex_load_attr
,
};
mp_obj_t
mp_obj_new_complex
(
mp_float_t
real
,
mp_float_t
imag
)
{
...
...
This diff is collapsed.
Click to expand it.
py/qstrdefs.h
+
4
−
0
View file @
f20375ee
...
...
@@ -136,7 +136,11 @@ Q(calcsize)
Q
(
chr
)
Q
(
classmethod
)
Q
(
_collections
)
#if MICROPY_PY_BUILTINS_COMPLEX
Q
(
complex
)
Q
(
real
)
Q
(
imag
)
#endif
Q
(
dict
)
Q
(
dir
)
Q
(
divmod
)
...
...
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