diff options
| author | DavePutz <dwputz@gmail.com> | 2021-02-24 10:09:52 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-24 10:09:52 -0600 |
| commit | eeb89a97b4a8fa25fb38e4a5d5db78c0c3df9b15 (patch) | |
| tree | e18ea9f61c7930d1f21d72fb69125a0270558038 /py/objfloat.c | |
| parent | cec921f3747beccff10c2d2dfbc237c305083f62 (diff) | |
| parent | e41137c745af65b6342c7e2d3b09d8930eefedb0 (diff) | |
Merge pull request #41 from adafruit/main
Update from adafruit main
Diffstat (limited to 'py/objfloat.c')
| -rw-r--r-- | py/objfloat.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/py/objfloat.c b/py/objfloat.c index 80f10e816..329a8b90e 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -340,6 +340,15 @@ mp_float_t uint64_to_float(uint64_t ui64) { return (mp_float_t) ((uint32_t) (ui64 >> 32) * 4294967296.0f + (uint32_t) (ui64 & 0xffffffff)); } +// Convert a uint64_t to a 32-bit float to a uint64_t without invoking extra math routines. +// which are large. +// Assume f >= 0. +uint64_t float_to_uint64(float f) { + // 4294967296 = 2^32 + const uint32_t upper_half = (uint32_t) (f / 4294967296.0f); + const uint32_t lower_half = (uint32_t) f; + return (((uint64_t) upper_half) << 32) + lower_half; +} #pragma GCC diagnostic pop #endif // MICROPY_PY_BUILTINS_FLOAT |
