Open hsenag opened 5 years ago
A consequence of the Rational encoding for numbers is that -0.0 :: Float can't be represented:
Rational
-0.0 :: Float
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.:
https://github.com/ChaiScript/ChaiScript/issues/334 https://github.com/google/gson/issues/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.
FWIW aeson also doesn't roundtrip -0.0, though it does print it correctly so presumably its data representation (Scientific) can handle it.
aeson
Scientific
A consequence of the
Rational
encoding for numbers is that-0.0 :: Float
can't be represented:Most JSON libraries do seem to have decided to roundtrip that correctly, e.g.:
https://github.com/ChaiScript/ChaiScript/issues/334 https://github.com/google/gson/issues/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.