After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 672143 - Float values are changed when they become interpreted
Float values are changed when they become interpreted
Status: RESOLVED NOTABUG
Product: json-glib
Classification: Core
Component: Core
0.14.x
Other Linux
: Normal normal
: ---
Assigned To: json-glib-maint
json-glib-maint
Depends on:
Blocks:
 
 
Reported: 2012-03-15 14:34 UTC by Marcin Lewandowski
Modified: 2012-09-18 08:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case (409 bytes, text/x-vala)
2012-03-15 14:34 UTC, Marcin Lewandowski
Details

Description Marcin Lewandowski 2012-03-15 14:34:02 UTC
Created attachment 209842 [details]
Test case

Please consider attached example.

It just reads {'a' : 123.231}, passes interpreted structure to the generator and then, serializes it again to JSON.

Output is {"a":123.23099999999999}

I understand that internal routines for float handling makes this change but this is behavior that is rather unpredictable for the programmer and should not behave like that.

E.g. I am making kind of message bus that is based on JSON, and I have to be sure that message that I forward to the client is *exactly* the same as what I received. It is impossible with current approach.

valac 0.14
json-glib 0.14.0
Comment 1 Emmanuele Bassi (:ebassi) 2012-09-18 08:48:20 UTC
it should behave exactly like that; your use case is an unreasonable expectation.

floating point values cannot be "exactly" the same as received. we also cannot lose precision because it's an all-or-nothing kind of situation: if we truncated the floating point values it would be fully arbitrary, and it would lead to loss of precision - you set 0.000334 and on the other end of the wire you get 0.000.

JSON is a data exchange format: accuracy of representation beats readability or character-by-character exactness.