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
GitLab 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
aedb8591
Commit
aedb8591
authored
9 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Make float representation configurable with object representation.
parent
7e359c64
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
+4
-0
4 additions, 0 deletions
py/obj.c
py/obj.h
+22
-8
22 additions, 8 deletions
py/obj.h
py/objfloat.c
+8
-8
8 additions, 8 deletions
py/objfloat.c
with
34 additions
and
16 deletions
py/obj.c
+
4
−
0
View file @
aedb8591
...
...
@@ -44,6 +44,10 @@ mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in) {
return
(
mp_obj_t
)
&
mp_type_int
;
}
else
if
(
MP_OBJ_IS_QSTR
(
o_in
))
{
return
(
mp_obj_t
)
&
mp_type_str
;
#if MICROPY_PY_BUILTINS_FLOAT
}
else
if
(
mp_obj_is_float
(
o_in
))
{
return
(
mp_obj_t
)
&
mp_type_float
;
#endif
}
else
{
const
mp_obj_base_t
*
o
=
o_in
;
return
(
mp_obj_t
)
o
->
type
;
...
...
This diff is collapsed.
Click to expand it.
py/obj.h
+
22
−
8
View file @
aedb8591
...
...
@@ -83,6 +83,17 @@ static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
#define MP_OBJ_QSTR_VALUE(o) (((mp_uint_t)(o)) >> 2)
#define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
#if MICROPY_PY_BUILTINS_FLOAT
#define mp_const_float_e ((mp_obj_t)&mp_const_float_e_obj)
#define mp_const_float_pi ((mp_obj_t)&mp_const_float_pi_obj)
extern
const
struct
_mp_obj_float_t
mp_const_float_e_obj
;
extern
const
struct
_mp_obj_float_t
mp_const_float_pi_obj
;
#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_new_float
(
mp_float_t
value
);
#endif
static
inline
bool
MP_OBJ_IS_OBJ
(
mp_const_obj_t
o
)
{
return
((((
mp_int_t
)(
o
))
&
3
)
==
0
);
}
...
...
@@ -98,6 +109,17 @@ static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
#define MP_OBJ_QSTR_VALUE(o) (((mp_uint_t)(o)) >> 2)
#define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 3))
#if MICROPY_PY_BUILTINS_FLOAT
#define mp_const_float_e ((mp_obj_t)&mp_const_float_e_obj)
#define mp_const_float_pi ((mp_obj_t)&mp_const_float_pi_obj)
extern
const
struct
_mp_obj_float_t
mp_const_float_e_obj
;
extern
const
struct
_mp_obj_float_t
mp_const_float_pi_obj
;
#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_new_float
(
mp_float_t
value
);
#endif
static
inline
bool
MP_OBJ_IS_OBJ
(
mp_const_obj_t
o
)
{
return
((((
mp_int_t
)(
o
))
&
1
)
==
0
);
}
...
...
@@ -473,7 +495,6 @@ mp_obj_t mp_obj_new_bytearray(mp_uint_t n, void *items);
mp_obj_t
mp_obj_new_bytearray_by_ref
(
mp_uint_t
n
,
void
*
items
);
#if MICROPY_PY_BUILTINS_FLOAT
mp_obj_t
mp_obj_new_int_from_float
(
mp_float_t
val
);
mp_obj_t
mp_obj_new_float
(
mp_float_t
val
);
mp_obj_t
mp_obj_new_complex
(
mp_float_t
real
,
mp_float_t
imag
);
#endif
mp_obj_t
mp_obj_new_exception
(
const
mp_obj_type_t
*
exc_type
);
...
...
@@ -564,13 +585,6 @@ void mp_str_print_quoted(const mp_print_t *print, const byte *str_data, mp_uint_
#if MICROPY_PY_BUILTINS_FLOAT
// float
#define mp_const_float_e ((mp_obj_t)&mp_const_float_e_obj)
#define mp_const_float_pi ((mp_obj_t)&mp_const_float_pi_obj)
extern
const
struct
_mp_obj_float_t
mp_const_float_e_obj
;
extern
const
struct
_mp_obj_float_t
mp_const_float_pi_obj
;
#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
// complex
...
...
This diff is collapsed.
Click to expand it.
py/objfloat.c
+
8
−
8
View file @
aedb8591
...
...
@@ -49,7 +49,7 @@ const mp_obj_float_t mp_const_float_pi_obj = {{&mp_type_float}, M_PI};
STATIC
void
float_print
(
const
mp_print_t
*
print
,
mp_obj_t
o_in
,
mp_print_kind_t
kind
)
{
(
void
)
kind
;
mp_
obj_
float_t
*
o
=
o_in
;
mp_float_t
o_val
=
mp_obj_float_get
(
o_in
)
;
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
char
buf
[
16
];
const
int
precision
=
7
;
...
...
@@ -57,7 +57,7 @@ STATIC void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
char
buf
[
32
];
const
int
precision
=
16
;
#endif
mp_format_float
(
o
->
val
ue
,
buf
,
sizeof
(
buf
),
'g'
,
precision
,
'\0'
);
mp_format_float
(
o
_
val
,
buf
,
sizeof
(
buf
),
'g'
,
precision
,
'\0'
);
mp_print_str
(
print
,
buf
);
if
(
strchr
(
buf
,
'.'
)
==
NULL
&&
strchr
(
buf
,
'e'
)
==
NULL
&&
strchr
(
buf
,
'n'
)
==
NULL
)
{
// Python floats always have decimal point (unless inf or nan)
...
...
@@ -91,24 +91,24 @@ STATIC mp_obj_t float_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
}
STATIC
mp_obj_t
float_unary_op
(
mp_uint_t
op
,
mp_obj_t
o_in
)
{
mp_obj_float_
t
*
o
=
o_in
;
mp_float_t
val
=
mp_obj_float_
get
(
o_in
)
;
switch
(
op
)
{
case
MP_UNARY_OP_BOOL
:
return
mp_obj_new_bool
(
o
->
val
ue
!=
0
);
case
MP_UNARY_OP_BOOL
:
return
mp_obj_new_bool
(
val
!=
0
);
case
MP_UNARY_OP_POSITIVE
:
return
o_in
;
case
MP_UNARY_OP_NEGATIVE
:
return
mp_obj_new_float
(
-
o
->
val
ue
);
case
MP_UNARY_OP_NEGATIVE
:
return
mp_obj_new_float
(
-
val
);
default:
return
MP_OBJ_NULL
;
// op not supported
}
}
STATIC
mp_obj_t
float_binary_op
(
mp_uint_t
op
,
mp_obj_t
lhs_in
,
mp_obj_t
rhs_in
)
{
mp_
obj_
float_t
*
lhs
=
lhs_in
;
mp_float_t
lhs
_val
=
mp_obj_float_get
(
lhs_in
)
;
#if MICROPY_PY_BUILTINS_COMPLEX
if
(
MP_OBJ_IS_TYPE
(
rhs_in
,
&
mp_type_complex
))
{
return
mp_obj_complex_binary_op
(
op
,
lhs
->
val
ue
,
0
,
rhs_in
);
return
mp_obj_complex_binary_op
(
op
,
lhs
_
val
,
0
,
rhs_in
);
}
else
#endif
{
return
mp_obj_float_binary_op
(
op
,
lhs
->
val
ue
,
rhs_in
);
return
mp_obj_float_binary_op
(
op
,
lhs
_
val
,
rhs_in
);
}
}
...
...
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