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
b8a053ae
Commit
b8a053ae
authored
11 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Implement float and complex == and !=.
Addresses issue #462.
parent
686afc5c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
py/obj.c
+16
-28
16 additions, 28 deletions
py/obj.c
py/objcomplex.c
+2
-0
2 additions, 0 deletions
py/objcomplex.c
py/objfloat.c
+1
-0
1 addition, 0 deletions
py/objfloat.c
with
19 additions
and
28 deletions
py/obj.c
+
16
−
28
View file @
b8a053ae
...
@@ -149,31 +149,20 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
...
@@ -149,31 +149,20 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
if
(
MP_OBJ_IS_SMALL_INT
(
o1
)
&&
MP_OBJ_IS_SMALL_INT
(
o2
))
{
if
(
MP_OBJ_IS_SMALL_INT
(
o1
)
&&
MP_OBJ_IS_SMALL_INT
(
o2
))
{
return
false
;
return
false
;
}
else
{
}
else
{
if
(
MP_OBJ_IS_SMALL_INT
(
o2
))
{
if
(
MP_OBJ_IS_SMALL_INT
(
o1
))
{
mp_obj_t
temp
=
o1
;
o1
=
o2
;
o2
=
temp
;
mp_obj_t
temp
=
o2
;
o2
=
o1
;
o1
=
temp
;
}
// o1 is the SMALL_INT, o2 is not
mp_small_int_t
val
=
MP_OBJ_SMALL_INT_VALUE
(
o1
);
if
(
o2
==
mp_const_false
)
{
return
val
==
0
;
}
else
if
(
o2
==
mp_const_true
)
{
return
val
==
1
;
}
else
if
(
MP_OBJ_IS_TYPE
(
o2
,
&
mp_type_int
))
{
// If o2 is long int, dispatch to its virtual methods
mp_obj_base_t
*
o
=
o2
;
if
(
o
->
type
->
binary_op
!=
NULL
)
{
mp_obj_t
r
=
o
->
type
->
binary_op
(
MP_BINARY_OP_EQUAL
,
o2
,
o1
);
return
r
==
mp_const_true
?
true
:
false
;
}
}
}
return
false
;
// o2 is the SMALL_INT, o1 is not
// fall through to generic op
}
}
}
else
if
(
MP_OBJ_IS_STR
(
o1
)
&&
MP_OBJ_IS_STR
(
o2
))
{
}
else
if
(
MP_OBJ_IS_STR
(
o1
)
&&
MP_OBJ_IS_STR
(
o2
))
{
return
mp_obj_str_equal
(
o1
,
o2
);
return
mp_obj_str_equal
(
o1
,
o2
);
}
else
{
}
mp_obj_base_t
*
o
=
o1
;
if
(
o
->
type
->
binary_op
!=
NULL
)
{
// generic type, call binary_op(MP_BINARY_OP_EQUAL)
mp_obj_t
r
=
o
->
type
->
binary_op
(
MP_BINARY_OP_EQUAL
,
o1
,
o2
);
mp_obj_type_t
*
type
=
mp_obj_get_type
(
o1
);
if
(
type
->
binary_op
!=
NULL
)
{
mp_obj_t
r
=
type
->
binary_op
(
MP_BINARY_OP_EQUAL
,
o1
,
o2
);
if
(
r
!=
MP_OBJ_NULL
)
{
if
(
r
!=
MP_OBJ_NULL
)
{
return
r
==
mp_const_true
?
true
:
false
;
return
r
==
mp_const_true
?
true
:
false
;
}
}
...
@@ -183,7 +172,6 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
...
@@ -183,7 +172,6 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
"Equality for '%s' and '%s' types not yet implemented"
,
mp_obj_get_type_str
(
o1
),
mp_obj_get_type_str
(
o2
)));
"Equality for '%s' and '%s' types not yet implemented"
,
mp_obj_get_type_str
(
o1
),
mp_obj_get_type_str
(
o2
)));
return
false
;
return
false
;
}
}
}
machine_int_t
mp_obj_get_int
(
mp_obj_t
arg
)
{
machine_int_t
mp_obj_get_int
(
mp_obj_t
arg
)
{
// This function essentially performs implicit type conversion to int
// This function essentially performs implicit type conversion to int
...
...
This diff is collapsed.
Click to expand it.
py/objcomplex.c
+
2
−
0
View file @
b8a053ae
...
@@ -205,6 +205,8 @@ mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_im
...
@@ -205,6 +205,8 @@ mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_im
break
;
break
;
}
}
case
MP_BINARY_OP_EQUAL
:
return
MP_BOOL
(
lhs_real
==
rhs_real
&&
lhs_imag
==
rhs_imag
);
default:
default:
return
MP_OBJ_NULL
;
// op not supported
return
MP_OBJ_NULL
;
// op not supported
}
}
...
...
This diff is collapsed.
Click to expand it.
py/objfloat.c
+
1
−
0
View file @
b8a053ae
...
@@ -132,6 +132,7 @@ check_zero_division:
...
@@ -132,6 +132,7 @@ check_zero_division:
case
MP_BINARY_OP_INPLACE_POWER
:
lhs_val
=
MICROPY_FLOAT_C_FUN
(
pow
)(
lhs_val
,
rhs_val
);
break
;
case
MP_BINARY_OP_INPLACE_POWER
:
lhs_val
=
MICROPY_FLOAT_C_FUN
(
pow
)(
lhs_val
,
rhs_val
);
break
;
case
MP_BINARY_OP_LESS
:
return
MP_BOOL
(
lhs_val
<
rhs_val
);
case
MP_BINARY_OP_LESS
:
return
MP_BOOL
(
lhs_val
<
rhs_val
);
case
MP_BINARY_OP_MORE
:
return
MP_BOOL
(
lhs_val
>
rhs_val
);
case
MP_BINARY_OP_MORE
:
return
MP_BOOL
(
lhs_val
>
rhs_val
);
case
MP_BINARY_OP_EQUAL
:
return
MP_BOOL
(
lhs_val
==
rhs_val
);
case
MP_BINARY_OP_LESS_EQUAL
:
return
MP_BOOL
(
lhs_val
<=
rhs_val
);
case
MP_BINARY_OP_LESS_EQUAL
:
return
MP_BOOL
(
lhs_val
<=
rhs_val
);
case
MP_BINARY_OP_MORE_EQUAL
:
return
MP_BOOL
(
lhs_val
>=
rhs_val
);
case
MP_BINARY_OP_MORE_EQUAL
:
return
MP_BOOL
(
lhs_val
>=
rhs_val
);
...
...
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