GaloisInc / json

Haskell JSON library
Other
27 stars 10 forks source link

Can't represent negative zero #8

Open hsenag opened 5 years ago

hsenag commented 5 years ago

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.:

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.

hsenag commented 5 years ago

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