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:
|
|
|
|
import sys
|
|
|
|
print("SKIP")
|
|
|
|
sys.exit()
|
2015-01-24 21:50:34 -05: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'))
|
|
|
|
|