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

formatRealFloat rounds numbers differently than Numeric counterparts #105

Closed
RyanGlScott opened this issue Dec 11, 2014 · 1 comment
Closed

Comments

@RyanGlScott
Copy link
Member

Using formatRealFloat from Data.Text.Lazy.Builder.RealFloat on GHC 7.8.3 sometimes rounds decimals differently than the show*Float functions from Numeric. An example:

> showGFloat (Just 4) (0.12345 :: Float) ""
"0.1234"
> formatRealFloat Generic (Just 4) (0.12345 :: Float)
"0.1235"

Upon a quick glance, it looks like this discrepancy is caused by the roundTo function in Data.Text.Internal.Builder.RealFloat.Functions. The implementation seems to be based off of the identically named function roundTo in GHC.Float (at least, up to base-4.5.1.0). In base-4.6.0.0, however, the implementation of roundTo was changed, which would expain the different results.

Perhaps using CPP pragmas to produce the correct implementation of roundTo depending on which version of base is being used would fix this problem?

@bos
Copy link
Contributor

bos commented Dec 12, 2014

Thanks. I've released the fix as 1.2.0.3.

@bos bos closed this as completed Dec 12, 2014
jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Dec 13, 2014
changelog:
1.2.0.3

* Update formatRealFloat to correspond to the definition in versions
  of base newer than 4.5 (haskell/text#105)
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