py: Add support for floats in mp_binary_{get,set}_val()

- This then provides support for floats in the struct package
This commit is contained in:
David Steinberg
2015-01-25 02:50:34 +00:00
committed by Paul Sokolovsky
parent a5efcd4745
commit 0b3014ce3a
2 changed files with 41 additions and 0 deletions

View File

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