-
Notifications
You must be signed in to change notification settings - Fork 37
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
JSON compliant to_chars? #65
Comments
Also, a number like 10.1 right now prints as 1.01E1, which adds 2 additional characters to the output, and it is harder for users to read. I'm curious if you know what the performance impact of supporting this cleaner output would be? |
Hi, thanks a lot for your interest! Since this is a duplicate of #35 I'm closing this, but please feel free to discuss further in this thread (or in #35) if you want. To answer your specific questions:
You're right, please read my answer in #35.
Maybe in the future, but not planned at this moment. PR is welcome though! Ideally, a hypothetical
I'm not sure. I will not be surprised either way. I think I saw supporting evidences in both ways.
To be absolutely honest, I really want to move away from header-only library 😃 |
Thanks for your helpful reply. I will probably develop a I appreciate the prompt reply! |
Thank you so much! |
Using modified code from yyjson and Glaze I was able to incorporate dragonbox and serialize in the desired JSON format. I'm sure the performance can be improved, but it is quite efficient in its current form. Thanks for your library, it made this very straightforward! |
Didn't check all the details but looks pretty good to me. Just have a couple of comments: As far as I can see this function does not remove trailing zeros, but is named as For IEEE-754 binary32, the exponent is at most of two decimal digits so you don't need this branching. Your implementation does have the correct rounding issue I mentioned, but of course it is not necessarily a real issue depending on your goal. IIRC the JSON spec doesn't really mandate correct rounding, just roundtrip guarantee, but not sure if I'm remembering correctly. In any case I think it's good to be aware of this.
Really glad my work is being integrated into such a great library! Also I love those small branchless tricks. Reminds me that I'm not really good at micro-optimizations lol |
Yeah, I had at first intended to trim and then realized it was simpler to use dragonbox's trimming. I updated the name.
Thanks for this observation.
Round-tripping and shortness are the primary goals. So, I also think this is okay. Also, I had to make a fix for denormalized float writing as JSON requires a 0 before the exponent. E.G. -1.E-47 must be written as "-1.0E-47" |
So I looked it up, and it seems the spec is very blurry in this respect, and basically allows the implementations to do whatever they want. So.... whatever. |
I'd like to use dragonbox for serializing floats in Glaze. What I'm particularly looking for is a JSON compliant
to_chars
implementation that has the shortest string result. It seems like dragonbox'sto_chars
will print out...E0
when it is not necessary.The other requirement for JSON compliance is that infinity and nan should be printed as
"null"
.Could options to support these features be added to dragonbox or should I fork the code and edit it myself?
I'd also like the
to_chars
to be header only, but I don't mind doing this conversion myself and keeping it up to date withdragonbox
.Thanks for all the hard work you've put into this great library!
The text was updated successfully, but these errors were encountered: