1# test struct package with floats 2try: 3 try: 4 import ustruct as struct 5 except: 6 import struct 7except ImportError: 8 print("SKIP") 9 raise SystemExit 10 11i = 1.0 + 1 / 2 12# TODO: it looks like '=' format modifier is not yet supported 13# for fmt in ('f', 'd', '>f', '>d', '<f', '<d', '=f', '=d'): 14for fmt in ("f", "d", ">f", ">d", "<f", "<d"): 15 x = struct.pack(fmt, i) 16 v = struct.unpack(fmt, x)[0] 17 print("%2s: %.17f - %s" % (fmt, v, (i == v) and "passed" or "failed")) 18