summaryrefslogtreecommitdiff
path: root/py/objfloat.c
diff options
context:
space:
mode:
authorBenjamin Shockley <benjaminshockley@hotmail.com>2021-01-03 10:41:16 -0600
committerGitHub <noreply@github.com>2021-01-03 10:41:16 -0600
commit8c8961ad0142a20793910363c8182c847b47bc58 (patch)
tree986358982921ccb6e887b0f0f5af39ec67709990 /py/objfloat.c
parent0084f0af24e4e219bc040c52ee723959423de6e2 (diff)
parent80fa60d4ef6a054cc481318caba96ef8d77fc026 (diff)
Merge pull request #3 from adafruit/main
Rebase
Diffstat (limited to 'py/objfloat.c')
-rw-r--r--py/objfloat.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/py/objfloat.c b/py/objfloat.c
index f544ade05..80f10e816 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
- * Copyright (c) 2013, 2014 Damien P. George
+ * SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -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