2015-01-24 21:50:34 -05:00
|
|
|
# test struct package with floats
|
2015-05-04 09:35:40 -04:00
|
|
|
try:
|
2023-08-22 11:15:46 -04:00
|
|
|
import struct
|
2017-03-08 18:11:05 -05:00
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
2017-06-08 00:00:57 -04:00
|
|
|
raise SystemExit
|
2015-01-24 21:50:34 -05:00
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
i = 1.0 + 1 / 2
|
2015-01-24 21:50:34 -05:00
|
|
|
# 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"):
|
2015-01-24 21:50:34 -05:00
|
|
|
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"))
|