summaryrefslogtreecommitdiffstatshomepage
path: root/tests/float/float_struct.py
blob: e55890a2cd4573a6fcff28b182c79f4085f56a6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# test struct package with floats

try:
    import ustruct as struct
except:
    import struct

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'))