float() consistency with python3
Posted: Tue Sep 11, 2018 12:41 pm
I am encountering slight differences in float() output between micropython and python3 in an alpine linux container, is this expected behavior?
Micropython:
~/aports/testing/micropython/src/micropython-1.9.4/tests $ ../ports/unix/micropython
MicroPython v3.8.0-1909-g685fa426c5-dirty on 2018-09-11; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> float('.' + '9' * 4)
0.9999000000000001
Python3:
~/aports/testing/micropython/src/micropython-1.9.4/tests $ python3
Python 3.6.6 (default, Aug 23 2018, 09:02:39)
[GCC 6.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> float('.' + '9' * 4)
0.9999
Additionally I see small differences using micropython on x86_64 vs ppc64le. Are these different results between cpu architectures expected behavior?
~/aports/testing/micropython/src/micropython-1.9.4/tests $ ../ports/unix/micropython
MicroPython v3.8.0-1909-g685fa426c5-dirty on 2018-09-11; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> float('.' + '9' * 70)
1.000000000000001
X86_64
Linux 1060f6cfbd6b
~/aports/testing/micropython/src/micropython-1.9.4/tests $ ../ports/unix/micropython
MicroPython v3.8.0-1909-g685fa426c5-dirty on 2018-09-11; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> float('.' + '9' * 70)
1.0
This last difference may explain why the float_parse.py test fails on ppc64le. Using python3 on ppc64le, float('.' + '9' * 70) returns 1.0. This causes float_parse.py test to fails because of the failed comparison to the micropython result (1.000000000000001).
Micropython:
~/aports/testing/micropython/src/micropython-1.9.4/tests $ ../ports/unix/micropython
MicroPython v3.8.0-1909-g685fa426c5-dirty on 2018-09-11; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> float('.' + '9' * 4)
0.9999000000000001
Python3:
~/aports/testing/micropython/src/micropython-1.9.4/tests $ python3
Python 3.6.6 (default, Aug 23 2018, 09:02:39)
[GCC 6.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> float('.' + '9' * 4)
0.9999
Additionally I see small differences using micropython on x86_64 vs ppc64le. Are these different results between cpu architectures expected behavior?
~/aports/testing/micropython/src/micropython-1.9.4/tests $ ../ports/unix/micropython
MicroPython v3.8.0-1909-g685fa426c5-dirty on 2018-09-11; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> float('.' + '9' * 70)
1.000000000000001
X86_64
Linux 1060f6cfbd6b
~/aports/testing/micropython/src/micropython-1.9.4/tests $ ../ports/unix/micropython
MicroPython v3.8.0-1909-g685fa426c5-dirty on 2018-09-11; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> float('.' + '9' * 70)
1.0
This last difference may explain why the float_parse.py test fails on ppc64le. Using python3 on ppc64le, float('.' + '9' * 70) returns 1.0. This causes float_parse.py test to fails because of the failed comparison to the micropython result (1.000000000000001).