Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
eabdf671
Commit
eabdf671
authored
Mar 22, 2014
by
Damien George
Browse files
py: Add function to convert long int to float.
parent
8138205b
Changes
5
Hide whitespace changes
Inline
Side-by-side
py/obj.c
View file @
eabdf671
...
...
@@ -176,6 +176,8 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
return
1
;
}
else
if
(
MP_OBJ_IS_SMALL_INT
(
arg
))
{
return
MP_OBJ_SMALL_INT_VALUE
(
arg
);
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
int_type
))
{
return
mp_obj_int_as_float
(
arg
);
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_float
))
{
return
mp_obj_float_get
(
arg
);
}
else
{
...
...
py/obj.h
View file @
eabdf671
...
...
@@ -330,6 +330,9 @@ void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj);
extern
const
mp_obj_type_t
int_type
;
// For long int, returns value truncated to machine_int_t
machine_int_t
mp_obj_int_get
(
mp_obj_t
self_in
);
#if MICROPY_ENABLE_FLOAT
mp_float_t
mp_obj_int_as_float
(
mp_obj_t
self_in
);
#endif
// Will rains exception if value doesn't fit into machine_int_t
machine_int_t
mp_obj_int_get_checked
(
mp_obj_t
self_in
);
...
...
py/objint.c
View file @
eabdf671
...
...
@@ -101,6 +101,12 @@ machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) {
return
MP_OBJ_SMALL_INT_VALUE
(
self_in
);
}
#if MICROPY_ENABLE_FLOAT
mp_float_t
mp_obj_int_as_float
(
mp_obj_t
self_in
)
{
return
MP_OBJ_SMALL_INT_VALUE
(
self_in
);
}
#endif
#endif // MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
const
mp_obj_type_t
int_type
=
{
...
...
py/objint_longlong.c
View file @
eabdf671
...
...
@@ -153,9 +153,10 @@ mp_obj_t mp_obj_new_int_from_long_str(const char *s) {
machine_int_t
mp_obj_int_get
(
mp_obj_t
self_in
)
{
if
(
MP_OBJ_IS_SMALL_INT
(
self_in
))
{
return
MP_OBJ_SMALL_INT_VALUE
(
self_in
);
}
else
{
mp_obj_int_t
*
self
=
self_in
;
return
self
->
val
;
}
mp_obj_int_t
*
self
=
self_in
;
return
self
->
val
;
}
machine_int_t
mp_obj_int_get_checked
(
mp_obj_t
self_in
)
{
...
...
@@ -163,4 +164,15 @@ machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) {
return
mp_obj_int_get
(
self_in
);
}
#if MICROPY_ENABLE_FLOAT
mp_float_t
mp_obj_int_as_float
(
mp_obj_t
self_in
)
{
if
(
MP_OBJ_IS_SMALL_INT
(
self_in
))
{
return
MP_OBJ_SMALL_INT_VALUE
(
self_in
);
}
else
{
mp_obj_int_t
*
self
=
self_in
;
return
self
->
val
;
}
}
#endif
#endif
py/objint_mpz.c
View file @
eabdf671
...
...
@@ -215,9 +215,10 @@ mp_obj_t mp_obj_new_int_from_long_str(const char *str) {
machine_int_t
mp_obj_int_get
(
mp_obj_t
self_in
)
{
if
(
MP_OBJ_IS_SMALL_INT
(
self_in
))
{
return
MP_OBJ_SMALL_INT_VALUE
(
self_in
);
}
else
{
mp_obj_int_t
*
self
=
self_in
;
return
mpz_as_int
(
&
self
->
mpz
);
}
mp_obj_int_t
*
self
=
self_in
;
return
mpz_as_int
(
&
self
->
mpz
);
}
machine_int_t
mp_obj_int_get_checked
(
mp_obj_t
self_in
)
{
...
...
@@ -225,4 +226,15 @@ machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) {
return
mp_obj_int_get
(
self_in
);
}
#if MICROPY_ENABLE_FLOAT
mp_float_t
mp_obj_int_as_float
(
mp_obj_t
self_in
)
{
if
(
MP_OBJ_IS_SMALL_INT
(
self_in
))
{
return
MP_OBJ_SMALL_INT_VALUE
(
self_in
);
}
else
{
mp_obj_int_t
*
self
=
self_in
;
return
mpz_as_float
(
&
self
->
mpz
);
}
}
#endif
#endif
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment