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:
|
|
|
|
import sys
|
|
|
|
print("SKIP")
|
|
|
|
sys.exit()
|
2015-01-25 02:50:34 +00:00
|
|
|
|
|
|
|
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'))
|
|
|
|
|