← index #1450Issue #11141
Related · high · value 0.245
QUERY · ISSUE

Single precision floating point formatting issues

openby dhylandsopened 2015-08-31updated 2024-08-28
docs

While investigating #1435 I ran into some other formatting issues. The output isn't necessarily wrong, but it doesn't match CPython either (although I am concerned about the outputting more data than requested potentially causing a buffer overflow).

1 - Outputting more data than requested.
On pyboard:

>>> '{:.4e}'.format(9.99999e-5)
'1.00000e-04'

On CPython:

>>> '{:.4e}'.format(9.99999e-5)
'1.0000e-04'

2 - making the wrong choice about when to use e notation:
pyboard:

>>> '%5.g' % 9.99999
'   10'

CPython:

>>> '%5.g' % 9.99999
'1e+01'

3 - Failing to normalize when rounding:
pyboard:

>>> '%5.e' % 9.99999
'10e+00'

CPython:

>>> '%5.e' % 9.99999
'1e+01'
CANDIDATE · ISSUE

Wrong float numbers in print()

closedby ondrejkarpisopened 2023-03-28updated 2023-03-28
bug

MicroPython v1.19.1 on 2022-06-18, ESP32 module
(esp32-20220618-v1.19.1.bin)

Tested code:
for i in range(0,1000):
print(1.0*i)

The above code should produce output in form
1.0
2.0
...
999.0

but, for some "i" it produces:
84.00001
89.00001
94.00001
99.00001
805.9999
809.9999
813.9999
817.9999
...

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