From da161fd9f025b624547b6ed5f74a0d30928310f1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 19 Mar 2016 21:59:42 +0000 Subject: extmod/uctypes: Finish support for FLOAT32 and FLOAT64 types. --- tests/extmod/uctypes_le_float.py | 20 ++++++++++++++++++++ tests/extmod/uctypes_le_float.py.exp | 3 +++ tests/extmod/uctypes_native_float.py | 16 ++++++++++++++++ tests/extmod/uctypes_native_float.py.exp | 2 ++ 4 files changed, 41 insertions(+) create mode 100644 tests/extmod/uctypes_le_float.py create mode 100644 tests/extmod/uctypes_le_float.py.exp create mode 100644 tests/extmod/uctypes_native_float.py create mode 100644 tests/extmod/uctypes_native_float.py.exp (limited to 'tests') 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 -- cgit v1.2.3