Comments (3)
This is a sticky corner case. It is, however, documented behavior in the README.md
(queue trumpets blaring). The passage in particular is:
Floating-point numbers are converted to their decimal representation using the
printf
format conversion specifier%.17g
. Theoretically this allows up to afloat
, or IEEE 754 Single 32-bit floating-point, worth of precision to be represented. This means that for practical purposes,double
values are converted tofloat
values with the associated loss of precision. The RFC 4627 standard is silent on how floating-point numbers should be dealt with and the author has found that real world JSON implementations vary wildly in how they handle this issue. Furthermore, the%g
format conversion specifier may convert floating-point values that can be exactly represented as an integer to a textual representation that does not include a.
ore
– essentially silently promoting a floating-point value to an integer value (i.e,5.0
becomes5
). Because of these and many other issues surrounding the conversion and manipulation of floating-point values, you should not expect or depend on floating point values to maintain their full precision, or when round tripped, to compare equal.
The very short answer: You're pretty much screwed. Fundamentally and throughly.
From the printf
documentation, I note the following (wrt/ #
modifier):
For
g
andG
conversions, trailing zeros are not removed from the result as they would otherwise be.
Yuck. So basically every single floating point number becomes 17 digits long. The cure is worst than the disease...
I'm sympathetic, but there's no obvious Right Thing(tm) to do, or way to handle it. :(
from jsonkit.
Hey John,
I understand and agree with pretty much everything you said, except that the cure is worse than the disease. I think that it's only slightly better than the disease, but my opinion may change :). I'm going to fork and make the change to add the # modifier for now.
from jsonkit.
Thanks for your response, by the way
from jsonkit.
Related Issues (20)
- Any popular replacement for JSONKit? HOT 2
- BSD two-clause or three-clause license? HOT 2
- crash at JSONKit.m:2598:77 HOT 2
- Error in serializing NSNumber HOT 2
- Supporting gzip decompression
- Swift HOT 7
- can not use with xcode 7 HOT 4
- Xcode 7 Before is use JSONKit in Object but now not use JSONKit in Xcode 7 HOT 7
- crash with iOS9 Xcode7 HOT 5
- Should be #import <JSONKit/JSONKit.h> or <GCJSONKit/JSONKit.h>? HOT 1
- please ignore
- Crash when NSDictionary to String json format. HOT 1
- about convert json to NSDictioanry (error if json string contains double field) HOT 7
- JsonKit message JSONDataWithOptions crashes in macOS Sierra HOT 1
- JSONKit Installation error in X-code 7.3.1 iOS 9.3 HOT 1
- iOS TRAP_TRACE crash
- JSONKit semantic issue after updating the pod HOT 3
- Tagged pointer format changes in iOS 14 break JSONKit on ARM64 HOT 8
- @serkrapiv Not necessarily verboten, just that they must be escaped. The first paragraph of 2.5 Strings says: HOT 1
- Yea
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonkit.