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

Encode RealFloat numbers using Scientific.fromFloatDigits #162

Merged
merged 3 commits into from Nov 19, 2013

Conversation

basvandijk
Copy link
Member

The previous code used realToFrac (fromRational . toRational) which approximates a floating point value. For example:

 > toRational (1.2::Double)
 5404319552844595 % 4503599627370496

If you encode this Rational number to a Scientific number and render it you get:

 > encode (1.2::Double)
 "1.1999999999999999555910790149937383830547332763671875"

Using Scientific.fromFloatDigits you get the expected:

 > encode (1.2::Double)
 "1.2"

The previous code used realToFrac (fromRation . toRational) which
approximates a floating point value. For example:

 > toRational (1.2::Double)
 5404319552844595 % 4503599627370496

If you encode this Rational number to a Scientific number and render it
you get:

 > encode (1.2::Double)
 "1.1999999999999999555910790149937383830547332763671875"

Using Scientific.fromFloatDigits you get the expected:

 > encode (1.2::Double)
 "1.2"
bos added a commit that referenced this pull request Nov 19, 2013
Encode RealFloat numbers using Scientific.fromFloatDigits
@bos bos merged commit b0b4c24 into haskell:master Nov 19, 2013
tolysz pushed a commit to tolysz/aeson that referenced this pull request May 18, 2015
Encode RealFloat numbers using Scientific.fromFloatDigits
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.

None yet

2 participants