micropython/tests/float/float_struct.py
Jim Mussared 4216bc7d13 tests: Replace umodule with module everywhere.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00

15 lines
440 B
Python

# test struct package with floats
try:
import struct
except ImportError:
print("SKIP")
raise SystemExit
i = 1.0 + 1 / 2
# TODO: it looks like '=' format modifier is not yet supported
# for fmt in ('f', 'd', '>f', '>d', '<f', '<d', '=f', '=d'):
for fmt in ("f", "d", ">f", ">d", "<f", "<d"):
x = struct.pack(fmt, i)
v = struct.unpack(fmt, x)[0]
print("%2s: %.17f - %s" % (fmt, v, (i == v) and "passed" or "failed"))