2017-02-14 17:56:22 -05:00
|
|
|
try:
|
|
|
|
import uctypes
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
2017-06-10 13:14:16 -04:00
|
|
|
raise SystemExit
|
2016-03-19 17:59:42 -04:00
|
|
|
|
|
|
|
desc = {
|
|
|
|
"f32": uctypes.FLOAT32 | 0,
|
|
|
|
"f64": uctypes.FLOAT64 | 0,
|
2021-03-15 09:57:36 -04:00
|
|
|
"uf64": uctypes.FLOAT64 | 2, # unaligned
|
2016-03-19 17:59:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
data = bytearray(10)
|
|
|
|
|
|
|
|
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
|
|
|
|
|
|
|
|
S.f32 = 12.34
|
2021-03-15 09:57:36 -04:00
|
|
|
print("%.4f" % S.f32)
|
2016-03-19 17:59:42 -04:00
|
|
|
|
|
|
|
S.f64 = 12.34
|
2021-03-15 09:57:36 -04:00
|
|
|
print("%.4f" % S.f64)
|
2016-03-19 17:59:42 -04:00
|
|
|
|
|
|
|
S.uf64 = 12.34
|
2021-03-15 09:57:36 -04:00
|
|
|
print("%.4f" % S.uf64)
|