2015-01-24 21:50:34 -05:00
|
|
|
# test struct package with floats
|
2015-05-04 09:35:40 -04:00
|
|
|
try:
|
2017-03-08 18:11:05 -05:00
|
|
|
try:
|
|
|
|
import ustruct as struct
|
|
|
|
except:
|
|
|
|
import struct
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
2017-06-08 00:00:57 -04:00
|
|
|
raise SystemExit
|
2015-01-24 21:50:34 -05:00
|
|
|
|
2020-03-22 22:26:08 -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'):
|
2020-03-22 22:26:08 -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]
|
2020-03-22 22:26:08 -04:00
|
|
|
print("%2s: %.17f - %s" % (fmt, v, (i == v) and "passed" or "failed"))
|