py/parsenum: Reduce code footprint of mp_parse_num_float.

The mantissa parsing code uses a floating point variable to accumulate
digits.  Using an `mp_float_uint_t` variable instead and casting to
`mp_float_t` at the very end reduces code size.  In some cases, it also
improves the rounding behaviour as extra digits are taken into account
by the int-to-float conversion code.

An extra test case handles the special case where mantissa overflow occurs
while processing deferred trailing zeros.

Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
This commit is contained in:
Yoctopuce dev
2025-01-30 10:23:06 +01:00
committed by Damien George
parent 50fab08e6b
commit 5fdd249c55
2 changed files with 17 additions and 11 deletions

View File

@@ -31,6 +31,9 @@ print(float("1e-4294967301"))
print(float("1e18446744073709551621"))
print(float("1e-18446744073709551621"))
# mantissa overflow while processing deferred trailing zeros
print(float("10000000000000000000001"))
# check small decimals are as close to their true value as possible
for n in range(1, 10):
print(float("0.%u" % n) == n / 10)