From 183edefddd8c08dd989fa7bec2d33d8b4130e1dc Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 17 Oct 2015 23:20:57 +0100 Subject: 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. --- py/objfloat.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'py/objfloat.c') 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 #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 -- cgit v1.2.3