summaryrefslogtreecommitdiff
path: root/tests/extmod
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-03-19 21:59:42 +0000
committerDamien George <damien.p.george@gmail.com>2016-03-19 21:59:42 +0000
commitda161fd9f025b624547b6ed5f74a0d30928310f1 (patch)
treea8ef4d36a75b69910999efade27fb4fc85f1fe76 /tests/extmod
parent12154b1774c0a05ce97af13307d106a76169ecc7 (diff)
extmod/uctypes: Finish support for FLOAT32 and FLOAT64 types.
Diffstat (limited to 'tests/extmod')
-rw-r--r--tests/extmod/uctypes_le_float.py20
-rw-r--r--tests/extmod/uctypes_le_float.py.exp3
-rw-r--r--tests/extmod/uctypes_native_float.py16
-rw-r--r--tests/extmod/uctypes_native_float.py.exp2
4 files changed, 41 insertions, 0 deletions
diff --git a/tests/extmod/uctypes_le_float.py b/tests/extmod/uctypes_le_float.py
new file mode 100644
index 000000000..c85b75f36
--- /dev/null
+++ b/tests/extmod/uctypes_le_float.py
@@ -0,0 +1,20 @@
+import uctypes
+
+desc = {
+ "f32": uctypes.FLOAT32 | 0,
+ "f64": uctypes.FLOAT64 | 0,
+ "uf64": uctypes.FLOAT64 | 2, # unaligned
+}
+
+data = bytearray(10)
+
+S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
+
+S.f32 = 12.34
+print('%.4f' % S.f32)
+
+S.f64 = 12.34
+print('%.4f' % S.f64)
+
+S.uf64 = 12.34
+print('%.4f' % S.uf64)
diff --git a/tests/extmod/uctypes_le_float.py.exp b/tests/extmod/uctypes_le_float.py.exp
new file mode 100644
index 000000000..a35a1da2d
--- /dev/null
+++ b/tests/extmod/uctypes_le_float.py.exp
@@ -0,0 +1,3 @@
+12.3400
+12.3400
+12.3400
diff --git a/tests/extmod/uctypes_native_float.py b/tests/extmod/uctypes_native_float.py
new file mode 100644
index 000000000..89aac8bf3
--- /dev/null
+++ b/tests/extmod/uctypes_native_float.py
@@ -0,0 +1,16 @@
+import uctypes
+
+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
+print('%.4f' % S.f32)
+
+S.f64 = 12.34
+print('%.4f' % S.f64)
diff --git a/tests/extmod/uctypes_native_float.py.exp b/tests/extmod/uctypes_native_float.py.exp
new file mode 100644
index 000000000..6abf0be70
--- /dev/null
+++ b/tests/extmod/uctypes_native_float.py.exp
@@ -0,0 +1,2 @@
+12.3400
+12.3400