py/parsenum: Fix parsing of floats that are close to subnormal. · csamuelson/circuitpython@b75cb83 · GitHub
Skip to content

Commit b75cb83

Browse files
committed
py/parsenum: Fix parsing of floats that are close to subnormal.
Prior to this patch, a float literal that was close to subnormal would have a loss of precision when parsed. The worst case was something like float('10000000000000000000e-326') which returned 0.0.
1 parent 0c650d4 commit b75cb83

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

py/parsenum.c

Lines changed: 12 additions & 2 deletions

tests/float/float_parse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@
2020
print(float('.' + '0' * 60 + '1e10') == float('1e-51'))
2121
print(float('.' + '0' * 60 + '9e25'))
2222
print(float('.' + '0' * 60 + '9e40'))
23+
24+
# ensure that accuracy is retained when value is close to a subnormal
25+
print(float('1.00000000000000000000e-37'))
26+
print(float('10.0000000000000000000e-38'))
27+
print(float('100.000000000000000000e-39'))

tests/float/float_parse_doubleprec.py

Lines changed: 5 additions & 0 deletions

0 commit comments

Comments
 (0)