Skip to content
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

Fixed Point Rounding #679

Open
BebeSparkelSparkel opened this issue May 21, 2024 · 2 comments
Open

Fixed Point Rounding #679

BebeSparkelSparkel opened this issue May 21, 2024 · 2 comments

Comments

@BebeSparkelSparkel
Copy link
Contributor

A test for printing a floating point number of 12.345 with two decimal places checks for the result of "12.34". This matches with the result of showFFloat but @clyring is suggesting this is an error.

What should the result of formatDouble (standard places) be when it is the same distance to round up or down?

@clyring
Copy link
Member

clyring commented Jun 5, 2024

What should the result of formatDouble (standard places) be when it is the same distance to round up or down?

Rounding to even is the usual expected behavior when it really is the same distance to round up or down. But my point is that:

  • There is no value of type Double which exactly represents 12.345.
  • 12.345 :: Double therefore means the closest representable Double to the real number 12.345, which happens to be 0x1.8b0a3d70a3d71p3 and represents the rational number 6949617174986097 % 562949953421312.
  • This rational number is greater than 12.345, by approximately 6.4e-16, and is thus slightly closer to 12.35 than it is to 12.34.

Both base and bytestring have the same bug, and first round 0x1.8b0a3d70a3d71p3 to the minimum number of decimal digits needed to disambiguate it from its neighboring Doubles and only then round that intermediate result to two decimal digits, when the user has asked 0x1.8b0a3d70a3d71p3 to be rounded directly to two decimal digits.

@BebeSparkelSparkel
Copy link
Contributor Author

Seems like the choice is to have compatibility with base or be more correct.

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

No branches or pull requests

2 participants