← index #11843Issue #4132
Off-topic · high · value 2.660
QUERY · ISSUE

docs: non standard behaviour of float()

openby massimosalaopened 2023-06-22updated 2025-11-06
docs

See
https://github.com/micropython/micropython/issues/11735

The official page
https://docs.micropython.org/en/latest/genrst/builtin_types.html#float
should be updated about the different result of

float('_')

(and eventually other invalid inputs)
between Python and MicroPython.

CANDIDATE · ISSUE

Floating-point behavior is not consistent with IEEE754

closedby Eccoopened 2018-09-13updated 2018-12-04

For some reason, even the most simple floating-point operations yields results that don't match IEEE754. For instance, in uPy, 0.1+0.2 == 0.3 returns True, while it is False in CPython and every other programming language that uses IEEE754.

One might argue that uPy's behavior is better. In that case it might, but uPy also does some rounding errors, just not the same as everyone else… For example, 1000.4-1000 will yield 0.4000244 in uPy but 0.39999999999997726 in CPython, JavaScript (Chrome, Firefox), Ruby, etc…

Also it looks like uPy's behavior is not matching the Python standard, since https://docs.python.org/3/tutorial/floatingpoint.html explicitly says that 0.1+0.2 == 0.3 should return False.

This bug is reproducible on the uPy live web page.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied