Skip to content

py/formatfloat: Format all whole-number floats exactly. #6722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2022

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Aug 9, 2022

Fixes #6649.

micropython@f9cbe6b is a fix to MicroPython that improves the representation of printed floats noticeably.

From the MicroPython PR:

Formerly, py/formatfloat would print whole numbers inaccurately with nonzero digits beyond the decimal place. This resulted from its strategy of successive scaling of the argument by 0.1 which cannot be exactly represented in floating point. The change in this commit avoids scaling until the value is smaller than 1, so all whole numbers print with zero fractional part.

Formerly, py/formatfloat would print whole numbers inaccurately with
nonzero digits beyond the decimal place.  This resulted from its strategy
of successive scaling of the argument by 0.1 which cannot be exactly
represented in floating point.  The change in this commit avoids scaling
until the value is smaller than 1, so all whole numbers print with zero
fractional part.

Fixes issue adafruit#4212.

Signed-off-by: Dan Ellis [email protected]
@dhalbert dhalbert added this to the 8.0.0 milestone Aug 10, 2022
@dhalbert dhalbert requested a review from tannewt August 10, 2022 12:31
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tannewt tannewt merged commit 741a5c2 into adafruit:main Aug 10, 2022
@dhalbert dhalbert deleted the micropython-float-print-fix branch September 5, 2022 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorporate MicroPython float printing fix
3 participants