circuitpython/tests/float/float_struct.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

15 lines
440 B
Python
Raw Normal View History

# test struct package with floats
try:
2023-08-22 11:15:46 -04:00
import struct
except ImportError:
print("SKIP")
raise SystemExit
2021-03-15 09:57:36 -04:00
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'):
2021-03-15 09:57:36 -04:00
for fmt in ("f", "d", ">f", ">d", "<f", "<d"):
x = struct.pack(fmt, i)
v = struct.unpack(fmt, x)[0]
2021-03-15 09:57:36 -04:00
print("%2s: %.17f - %s" % (fmt, v, (i == v) and "passed" or "failed"))