diff options
| author | Dan Halbert <halbert@adafruit.com> | 2021-02-21 17:27:16 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-21 17:27:16 -0500 |
| commit | 79b12267595680497e53bae7154f4b6aa607cc89 (patch) | |
| tree | 036b3da97426b08697743d260385994e7a82f01c /py/objfloat.c | |
| parent | 2830984aef2208abe911e1a6143e084293e3fc9c (diff) | |
| parent | 93bf269c0d56ec5d842ff908e149c635ab323107 (diff) | |
Merge pull request #4238 from dhalbert/cdc-avoid-extra-float-libs
usb_cdc: avoid pulling in extra float-uint64 routines
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 |
