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

Why 3 types of number? #48

Closed
calebmer opened this issue Mar 2, 2016 · 4 comments
Closed

Why 3 types of number? #48

calebmer opened this issue Mar 2, 2016 · 4 comments
Labels

Comments

@calebmer
Copy link

calebmer commented Mar 2, 2016

Just an innocent question, I'm curious to here the reason for three types (F64, U64, and I64) of what is ultimately typed in JSON as a number. This may betray the fact that I was never a low level programmer, but even if there is a low level reason I'd like to know it. Thanks for the great open source project 😊

@erickt
Copy link
Member

erickt commented Mar 2, 2016

Json doesn't define what a number means, so we err here on flexibility in order to avoid losing precision. If we only had a single f64 for our numbers, it could only precisely represent the integers up to -253 to 253. This protects us from, say, someone using a random u64 and an id.

One downside with our approach is that serde doesn't yet provide a good model for arbitrarily sized integers, so we cut things off at 64 bytes. If I recall correctly, this is the same behavior as RapidJSON and the various java parsers so I figured it wouldn't be a significant impact.

@erickt erickt closed this as completed Mar 2, 2016
@calebmer
Copy link
Author

calebmer commented Mar 2, 2016

Ok, thanks! 😊

@dtolnay
Copy link
Member

dtolnay commented Apr 25, 2016

I am not convinced by the justification. I filed #57 to follow up after #18 is resolved.

@dtolnay
Copy link
Member

dtolnay commented Feb 13, 2017

This was fixed in #188 / serde_json 0.9.0. Now there is one serde_json::Value::Number variant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants