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

Can't represent negative zero #8

Open
hsenag opened this issue Oct 10, 2018 · 1 comment
Open

Can't represent negative zero #8

hsenag opened this issue Oct 10, 2018 · 1 comment

Comments

@hsenag
Copy link

hsenag commented Oct 10, 2018

A consequence of the Rational encoding for numbers is that -0.0 :: Float can't be represented:

Prelude Text.JSON> readJSON (showJSON (-0 :: Float)) :: Result Float
Ok 0.0

Most JSON libraries do seem to have decided to roundtrip that correctly, e.g.:

ChaiScript/ChaiScript#334
google/gson#1053
https://www.ietf.org/mail-archive/web/json/current/msg03670.html

but it's not totally unambiguous, e.g.:

https://www.ietf.org/mail-archive/web/json/current/msg03927.html

Given that Rational is normalised on construction and can't represent negative zero, I don't think there's an easy fix though.

@hsenag
Copy link
Author

hsenag commented Oct 10, 2018

FWIW aeson also doesn't roundtrip -0.0, though it does print it correctly so presumably its data representation (Scientific) can handle it.

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

1 participant