You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
496 B
19 lines
496 B
4 years ago
|
# test struct package with floats
|
||
|
try:
|
||
|
try:
|
||
|
import ustruct as struct
|
||
|
except:
|
||
|
import struct
|
||
|
except ImportError:
|
||
|
print("SKIP")
|
||
|
raise SystemExit
|
||
|
|
||
|
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'))
|
||
|
|