diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/float/float_struct.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/float/float_struct.py b/tests/float/float_struct.py new file mode 100644 index 0000000000..8ad0e492c6 --- /dev/null +++ b/tests/float/float_struct.py @@ -0,0 +1,12 @@ +# test struct package with floats + +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')) + |