aboutsummaryrefslogtreecommitdiff
path: root/py/objfloat.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-10-17 23:20:57 +0100
committerDamien George <damien.p.george@gmail.com>2015-10-20 12:38:54 +0100
commit183edefddd8c08dd989fa7bec2d33d8b4130e1dc (patch)
tree530b4807c22868f556da2ce87f987e38bded7c25 /py/objfloat.c
parentaedb8591778a8dc4097eb4ffd2891dd5730efdde (diff)
py: Add object repr "C", where 30-bit floats are stuffed in obj word.
This new object representation puts floats into the object word instead of on the heap, at the expense of reducing their precision to 30 bits. It only makes sense when the word size is 32-bits.
Diffstat (limited to 'py/objfloat.c')
-rw-r--r--py/objfloat.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/py/objfloat.c b/py/objfloat.c
index 7c58f320d..81eac99bd 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -39,6 +39,8 @@
#include <math.h>
#include "py/formatfloat.h"
+#if MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_C
+
typedef struct _mp_obj_float_t {
mp_obj_base_t base;
mp_float_t value;
@@ -47,6 +49,8 @@ typedef struct _mp_obj_float_t {
const mp_obj_float_t mp_const_float_e_obj = {{&mp_type_float}, M_E};
const mp_obj_float_t mp_const_float_pi_obj = {{&mp_type_float}, M_PI};
+#endif
+
STATIC void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
(void)kind;
mp_float_t o_val = mp_obj_float_get(o_in);
@@ -121,6 +125,8 @@ const mp_obj_type_t mp_type_float = {
.binary_op = float_binary_op,
};
+#if MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_C
+
mp_obj_t mp_obj_new_float(mp_float_t value) {
mp_obj_float_t *o = m_new(mp_obj_float_t, 1);
o->base.type = &mp_type_float;
@@ -134,6 +140,8 @@ mp_float_t mp_obj_float_get(mp_obj_t self_in) {
return self->value;
}
+#endif
+
STATIC void mp_obj_float_divmod(mp_float_t *x, mp_float_t *y) {
// logic here follows that of CPython
// https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations