`repr()` of a float is not the shortest string that round-trips
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Start with py/formatfloat.c, especially mp_format_float() and the EXACT refinement described in the issue; compare its output requirements with CPython's shortest-round-trip behavior. Reproduce the provided float examples on the Unix port with EXACT and APPROX formats, then inspect relevant float formatting tests. Done means repr(), str(), and print() produce the shortest strings that round-trip across the reported formats.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Port, board and/or hardware
Unix port, Linux aarch64 (Debian 12) and macOS arm64
MicroPython version
MicroPython v1.30.0-preview-247-gcbbdb6379
Reproduction
print(repr(9.55365950890869))
print(repr(float(2**70)))
Expected behaviour
CPython prints (3.11.15):
9.55365950890869
1.1805916207174113e+21
Observed behaviour
Linux aarch64, where MICROPY_FLOAT_FORMAT_IMPL defaults to EXACT:
9.553659508908691
1.1805916207174113e+21
macOS arm64, where it defaults to APPROX:
9.55365950890869
1.1805916207174114e+21
Both MicroPython strings parse back to the same double, so only the printed form differs. The same shows in print(), str() and in the repr of containers, for example 8.16906041417051 printing as 8.169060414170509 and -830455.837990542 as -830455.8379905419 on Linux aarch64.
Additional Information
The EXACT format guarantees that repr() round-trips, which is what #17444 measured, but not that the string is the shortest one. CPython has printed the shortest round-tripping string since 3.1.
Root Cause
mp_format_float() starts from SAFE_MANTISSA_DIGITS (16 for double) and the EXACT refinement only adds digits until the value round-trips, so a value whose shortest form has 15 or fewer digits is printed with 16 when the 16th digit is not zero. CPython's float_repr() uses PyOS_double_to_string(v, 'r', ...), which is _Py_dg_dtoa mode 0, the shortest round-tripping string.
Code of Conduct
Yes, I agree
- Lingua principale
- C
- Stelle
- 22.2k
- Fork
- 9.1k
- Merge medio
- 6g 8h
- PR unite (30g)
- 33
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di micropython/micropython
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
micropython/micropython#19942 ·
I maintainer di solito rispondono entro 1 giorno
-
bug port-rp2
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
micropython/micropython#19933 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
micropython/micropython#19906 ·
I maintainer di solito rispondono entro 1 giorno
-
bug port-stm32
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
micropython/micropython#19905 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
micropython/micropython#19873 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di micropython/micropython
Issue simili
-
快速入门那里会不会对新手不太友好,提出优化方案Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
-
-disable-symbolserver is ignored on macOS/Linux: PDBs are still downloaded from msdl.microsoft.comAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
-
follow-up Prio 📌
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
facebookincubator/muse-gadget-sdk#384 ·
I maintainer di solito rispondono entro 5 giorni