Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
circuitpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
circuitpython
Commits
fdb2aa81
Commit
fdb2aa81
authored
Sep 18, 2017
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py/{objfloat,objcomplex}: Optimise MP_UNARY_OP_ABS by reusing variables.
parent
9dce823c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
8 deletions
+4
-8
py/objcomplex.c
py/objcomplex.c
+2
-5
py/objfloat.c
py/objfloat.c
+2
-3
No files found.
py/objcomplex.c
View file @
fdb2aa81
...
...
@@ -124,11 +124,8 @@ STATIC mp_obj_t complex_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
case
MP_UNARY_OP_HASH
:
return
MP_OBJ_NEW_SMALL_INT
(
mp_float_hash
(
o
->
real
)
^
mp_float_hash
(
o
->
imag
));
case
MP_UNARY_OP_POSITIVE
:
return
o_in
;
case
MP_UNARY_OP_NEGATIVE
:
return
mp_obj_new_complex
(
-
o
->
real
,
-
o
->
imag
);
case
MP_UNARY_OP_ABS
:
{
mp_float_t
real
,
imag
;
mp_obj_complex_get
(
o_in
,
&
real
,
&
imag
);
return
mp_obj_new_float
(
MICROPY_FLOAT_C_FUN
(
sqrt
)(
real
*
real
+
imag
*
imag
));
}
case
MP_UNARY_OP_ABS
:
return
mp_obj_new_float
(
MICROPY_FLOAT_C_FUN
(
sqrt
)(
o
->
real
*
o
->
real
+
o
->
imag
*
o
->
imag
));
default:
return
MP_OBJ_NULL
;
// op not supported
}
}
...
...
py/objfloat.c
View file @
fdb2aa81
...
...
@@ -163,10 +163,9 @@ STATIC mp_obj_t float_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
case
MP_UNARY_OP_POSITIVE
:
return
o_in
;
case
MP_UNARY_OP_NEGATIVE
:
return
mp_obj_new_float
(
-
val
);
case
MP_UNARY_OP_ABS
:
{
mp_float_t
value
=
mp_obj_float_get
(
o_in
);
// TODO check for NaN etc
if
(
val
ue
<
0
)
{
return
mp_obj_new_float
(
-
val
ue
);
if
(
val
<
0
)
{
return
mp_obj_new_float
(
-
val
);
}
else
{
return
o_in
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment