Skip to content

Commit e4af676

Browse files
committed
tests/float: Add test for exact float parsing.
Thanks to @ddiminnie for the extra test cases. Signed-off-by: Damien George <damien@micropython.org>
1 parent 92d4fa8 commit e4af676

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/float/float_parse_doubleprec.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,32 @@
1919
print(float("1.00000000000000000000e-307"))
2020
print(float("10.0000000000000000000e-308"))
2121
print(float("100.000000000000000000e-309"))
22+
23+
# ensure float is parsed exactly
24+
print(float("74e46"))
25+
26+
# Overflow/largest double boundary:
27+
print(float("1.7976931348623159e308")) # (should overflow, 0x000000000000f07f )
28+
print("%.15e" % float("1.7976931348623158e308")) # (should yield the max double, 0xffffffffffffef7f )
29+
30+
"""
31+
TODO get these working?
32+
# Normalized/denormalized double boundary
33+
print("%.16e" % float("2.2250738585072012e-308")) # (should yield smallest normalized double, 0x0000000000001000 )
34+
print("%.16e" % float("2.2250738585072011e-308")) # (should yield largest denormalized double, 0xffffffffffff0f00 )
35+
36+
# Shortest (up to) 17-digit input that converts to smallest denormalized double:
37+
print(float("5e-324")) # (should yield smallest denormalized double, 0x0100000000000000 )
38+
39+
# Closest 17-digit input to the smallest denormalized double:
40+
print(float("4.9406564584124654e-324")) # (should yield smallest denormalized double, 0x0100000000000000 )
41+
42+
# The next boundary will depend on how good the ldexp implementation is on the target platform:
43+
# Smallest denormalized double/underflow boundary:
44+
45+
print(float("2.4703282292062328e-324")) # (should yield smallest denormalized double, 0x0100000000000000 )
46+
# (Note that this value is greater than 2**-1075 and therefore should round up. 64-bit CPython 3.7.5 on win32 gets this right. Your mileage may vary, since the 54 most significant bits of the result are 0b1.00000000000000000000000000000000000000000000000000000 x 2**-1075.)
47+
"""
48+
49+
print(float("2.4703282292062327e-324")) # (should underflow to zero: 0x0000000000000000 )
50+
# (Note that this value is less than 2**-1075 and therefore should round down to zero.)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy