8000 tests/float/float_struct_e.py: Add specific test for struct 'e' type. · micropython/micropython@c11f827 · GitHub
[go: up one dir, main page]

Skip to content

Commit c11f827

Browse files
committed
tests/float/float_struct_e.py: Add specific test for struct 'e' type.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 68ad70e commit c11f827

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/float/float_struct_e.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Test struct pack/unpack with 'e' typecode.
2+
3+
try:
4+
import struct
5+
except ImportError:
6+
print("SKIP")
7+
raise SystemExit
8+
9+
test_values = (1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 0, 0.1, 1, 2, 4, 8, 10, 100, 1000, 1e4, 6e4)
10+
11+
for j in test_values:
12+
for i in (j, -j):
13+
x = struct.pack("e", i)
14+
v = struct.unpack("e", x)[0]
15+
print("%.7f %s %.15f %s" % (i, x, v, i == v))
16+
17+
# In CPython, packing a float that doesn't fit into a half-float raises OverflowError.
18+
# But in MicroPython it does not, but rather stores the value as inf.
19+
try:
20+
struct.pack("e", 1e15)
21+
except OverflowError:
22+
pass

0 commit comments

Comments
 (0)
0