circuitpython/tests/extmod/uctypes_native_float.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

18 lines
310 B
Python
Raw Permalink Normal View History

2017-02-14 17:56:22 -05:00
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
2021-03-15 09:57:36 -04:00
desc = {"f32": uctypes.FLOAT32 | 0, "f64": uctypes.FLOAT64 | 0}
data = bytearray(8)
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.NATIVE)
S.f32 = 12.34
2021-03-15 09:57:36 -04:00
print("%.4f" % S.f32)
S.f64 = 12.34
2021-03-15 09:57:36 -04:00
print("%.4f" % S.f64)