Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
micropython/tests/float/float_struct.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
14 lines (13 sloc)
457 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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")) |