2015-01-25 02:50:34 +00:00
|
|
|
# test struct package with floats
|
2015-05-04 14:35:40 +01:00
|
|
|
try:
|
2017-03-08 23:11:05 +00:00
|
|
|
try:
|
|
|
|
import ustruct as struct
|
|
|
|
except:
|
|
|
|
import struct
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
2017-06-08 05:00:57 +01:00
|
|
|
raise SystemExit
|
2015-01-25 02:50:34 +00:00
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
i = 1.0 + 1 / 2
|
2015-01-25 02:50:34 +00:00
|
|
|
# TODO: it looks like '=' format modifier is not yet supported
|
|
|
|
# for fmt in ('f', 'd', '>f', '>d', '<f', '<d', '=f', '=d'):
|
2020-03-23 02:26:08 +00:00
|
|
|
for fmt in ("f", "d", ">f", ">d", "<f", "<d"):
|
2015-01-25 02:50:34 +00:00
|
|
|
x = struct.pack(fmt, i)
|
|
|
|
v = struct.unpack(fmt, x)[0]
|
2020-03-23 02:26:08 +00:00
|
|
|
print("%2s: %.17f - %s" % (fmt, v, (i == v) and "passed" or "failed"))
|