circuitpython/tests/float/float_struct.py
Diego Elio Pettenò dd5d7c86d2 Fix up end of file and trailing whitespace.
This can be enforced by pre-commit, but correct it separately to make it easier to review.
2020-06-03 10:56:35 +01:00

18 lines
495 B
Python

# test struct package with floats
try:
try:
import ustruct as struct
except:
import struct
except ImportError:
print("SKIP")
raise SystemExit
i = 1. + 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'))