diff options
Diffstat (limited to 'tests/micropython/const_float.py')
-rw-r--r-- | tests/micropython/const_float.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/micropython/const_float.py b/tests/micropython/const_float.py new file mode 100644 index 000000000..c3a0df027 --- /dev/null +++ b/tests/micropython/const_float.py @@ -0,0 +1,23 @@ +# test constant optimisation, with consts that are floats + +from micropython import const + +# check we can make consts from floats +F1 = const(2.5) +F2 = const(-0.3) +print(type(F1), F1) +print(type(F2), F2) + +# check arithmetic with floats +F3 = const(F1 + F2) +F4 = const(F1**2) +print(F3, F4) + +# check int operations with float results +F5 = const(1 / 2) +F6 = const(2**-2) +print(F5, F6) + +# note: we also test float expression folding when +# we're compiling test cases in tests/float, as +# many expressions are resolved at compile time. |