summaryrefslogtreecommitdiff
path: root/py/objfloat.c
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-12-02 13:10:39 -0800
committerScott Shawcroft <scott@tannewt.org>2020-12-02 13:10:39 -0800
commit608c98501bb90e02a480b2d84032a46f9a4d0737 (patch)
treeadea018a0c0e714ef33b79a306b69885568b6ad0 /py/objfloat.c
parent34bbcc4910014c3b4646d8005baf8244bac51f03 (diff)
parentd7ba641ff646b48e5ad38ff72a2dcfe17bb54624 (diff)
Merge remote-tracking branch 'adafruit/main' into msgpack
Diffstat (limited to 'py/objfloat.c')
-rw-r--r--py/objfloat.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/py/objfloat.c b/py/objfloat.c
index 59f1eb2f6..80f10e816 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -333,6 +333,13 @@ mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t
return mp_obj_new_float(lhs_val);
}
+// Convert a uint64_t to a 32-bit float without invoking the double-precision math routines,
+// which are large.
+mp_float_t uint64_to_float(uint64_t ui64) {
+ // 4294967296 = 2^32
+ return (mp_float_t) ((uint32_t) (ui64 >> 32) * 4294967296.0f + (uint32_t) (ui64 & 0xffffffff));
+}
+
#pragma GCC diagnostic pop
#endif // MICROPY_PY_BUILTINS_FLOAT