haskell / bytestring

An efficient compact, immutable byte string type (both strict and lazy) suitable for binary or 8-bit character data.
http://hackage.haskell.org/package/bytestring
Other
291 stars 141 forks source link

Fixed Point Rounding #679

Open BebeSparkelSparkel opened 6 months ago

BebeSparkelSparkel commented 6 months ago

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 commented 5 months ago

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:

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 commented 5 months ago

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