mirror of
https://github.com/W3SLAV/micropython.git
synced 2025-06-19 03:55:44 -04:00

This commit implements the 'e' half-float format: 10-bit mantissa, 5-bit exponent. It uses native _Float16 if supported by the compiler, otherwise uses custom bitshifting encoding/decoding routines. Signed-off-by: Matthias Urlichs <matthias@urlichs.de> Signed-off-by: Damien George <damien@micropython.org>
15 lines
457 B
Python
15 lines
457 B
Python
# test struct package with floats
|
|
try:
|
|
import struct
|
|
except ImportError:
|
|
print("SKIP")
|
|
raise SystemExit
|
|
|
|
i = 1.0 + 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 ("e", "f", "d", ">e", ">f", ">d", "<e", "<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"))
|