Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
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
micropython
Commits
aaef1851
Commit
aaef1851
authored
Aug 20, 2015
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py: Add mp_obj_is_float function (macro) and use it where appropriate.
parent
60401d46
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
12 additions
and
11 deletions
+12
-11
py/modbuiltins.c
py/modbuiltins.c
+1
-1
py/obj.c
py/obj.c
+2
-2
py/obj.h
py/obj.h
+1
-0
py/objfloat.c
py/objfloat.c
+2
-2
py/objint.c
py/objint.c
+1
-1
py/objint_mpz.c
py/objint_mpz.c
+1
-1
py/objstr.c
py/objstr.c
+3
-3
py/runtime.c
py/runtime.c
+1
-1
No files found.
py/modbuiltins.c
View file @
aaef1851
...
...
@@ -93,7 +93,7 @@ STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
if
(
0
)
{
// dummy
#if MICROPY_PY_BUILTINS_FLOAT
}
else
if
(
MP_OBJ_IS_TYPE
(
o_in
,
&
mp_type_float
))
{
}
else
if
(
mp_obj_is_float
(
o_in
))
{
mp_float_t
value
=
mp_obj_float_get
(
o_in
);
// TODO check for NaN etc
if
(
value
<
0
)
{
...
...
py/obj.c
View file @
aaef1851
...
...
@@ -268,7 +268,7 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
return
MP_OBJ_SMALL_INT_VALUE
(
arg
);
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_int
))
{
return
mp_obj_int_as_float
(
arg
);
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_float
))
{
}
else
if
(
mp_obj_is_float
(
arg
))
{
return
mp_obj_float_get
(
arg
);
}
else
{
if
(
MICROPY_ERROR_REPORTING
==
MICROPY_ERROR_REPORTING_TERSE
)
{
...
...
@@ -295,7 +295,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_int
))
{
*
real
=
mp_obj_int_as_float
(
arg
);
*
imag
=
0
;
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_float
))
{
}
else
if
(
mp_obj_is_float
(
arg
))
{
*
real
=
mp_obj_float_get
(
arg
);
*
imag
=
0
;
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_complex
))
{
...
...
py/obj.h
View file @
aaef1851
...
...
@@ -568,6 +568,7 @@ typedef struct _mp_obj_float_t {
mp_obj_base_t
base
;
mp_float_t
value
;
}
mp_obj_float_t
;
#define mp_obj_is_float(o) MP_OBJ_IS_TYPE((o), &mp_type_float)
mp_float_t
mp_obj_float_get
(
mp_obj_t
self_in
);
mp_obj_t
mp_obj_float_binary_op
(
mp_uint_t
op
,
mp_float_t
lhs_val
,
mp_obj_t
rhs
);
// can return MP_OBJ_NULL if op not supported
...
...
py/objfloat.c
View file @
aaef1851
...
...
@@ -72,7 +72,7 @@ STATIC mp_obj_t float_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
mp_uint_t
l
;
const
char
*
s
=
mp_obj_str_get_data
(
args
[
0
],
&
l
);
return
mp_parse_num_decimal
(
s
,
l
,
false
,
false
,
NULL
);
}
else
if
(
MP_OBJ_IS_TYPE
(
args
[
0
],
&
mp_type_float
))
{
}
else
if
(
mp_obj_is_float
(
args
[
0
]
))
{
// a float, just return it
return
args
[
0
];
}
else
{
...
...
@@ -121,7 +121,7 @@ mp_obj_t mp_obj_new_float(mp_float_t value) {
}
mp_float_t
mp_obj_float_get
(
mp_obj_t
self_in
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp_type_float
));
assert
(
mp_obj_is_float
(
self_in
));
mp_obj_float_t
*
self
=
self_in
;
return
self
->
value
;
}
...
...
py/objint.c
View file @
aaef1851
...
...
@@ -60,7 +60,7 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_
const
char
*
s
=
mp_obj_str_get_data
(
args
[
0
],
&
l
);
return
mp_parse_num_integer
(
s
,
l
,
0
,
NULL
);
#if MICROPY_PY_BUILTINS_FLOAT
}
else
if
(
MP_OBJ_IS_TYPE
(
args
[
0
],
&
mp_type_float
))
{
}
else
if
(
mp_obj_is_float
(
args
[
0
]
))
{
return
mp_obj_new_int_from_float
(
mp_obj_float_get
(
args
[
0
]));
#endif
}
else
{
...
...
py/objint_mpz.c
View file @
aaef1851
...
...
@@ -178,7 +178,7 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
}
else
if
(
MP_OBJ_IS_TYPE
(
rhs_in
,
&
mp_type_int
))
{
zrhs
=
&
((
mp_obj_int_t
*
)
rhs_in
)
->
mpz
;
#if MICROPY_PY_BUILTINS_FLOAT
}
else
if
(
MP_OBJ_IS_TYPE
(
rhs_in
,
&
mp_type_float
))
{
}
else
if
(
mp_obj_is_float
(
rhs_in
))
{
return
mp_obj_float_binary_op
(
op
,
mpz_as_float
(
zlhs
),
rhs_in
);
#if MICROPY_PY_BUILTINS_COMPLEX
}
else
if
(
MP_OBJ_IS_TYPE
(
rhs_in
,
&
mp_type_complex
))
{
...
...
py/objstr.c
View file @
aaef1851
...
...
@@ -827,15 +827,15 @@ STATIC bool arg_looks_integer(mp_obj_t arg) {
STATIC
bool
arg_looks_numeric
(
mp_obj_t
arg
)
{
return
arg_looks_integer
(
arg
)
#if MICROPY_PY_BUILTINS_FLOAT
||
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_float
)
||
mp_obj_is_float
(
arg
)
#endif
;
}
STATIC
mp_obj_t
arg_as_int
(
mp_obj_t
arg
)
{
#if MICROPY_PY_BUILTINS_FLOAT
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_float
))
{
return
mp_obj_new_int_from_float
(
mp_obj_
get_floa
t
(
arg
));
if
(
mp_obj_is_float
(
arg
))
{
return
mp_obj_new_int_from_float
(
mp_obj_
float_ge
t
(
arg
));
}
#endif
return
arg
;
...
...
py/runtime.c
View file @
aaef1851
...
...
@@ -458,7 +458,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
return
mp_obj_new_int
(
lhs_val
);
}
#if MICROPY_PY_BUILTINS_FLOAT
}
else
if
(
MP_OBJ_IS_TYPE
(
rhs
,
&
mp_type_float
))
{
}
else
if
(
mp_obj_is_float
(
rhs
))
{
mp_obj_t
res
=
mp_obj_float_binary_op
(
op
,
lhs_val
,
rhs
);
if
(
res
==
MP_OBJ_NULL
)
{
goto
unsupported_op
;
...
...
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