-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Incorrect dumping of parsed numbers with exponents, but without decimal places #230
Comments
There is also an issue with other parsed numbers with exponents, but without decimal separator:
|
❗ This bug is currently a blocker for the 2.0.0 release, because the serialization of parsed numbers is not correct. |
Caveat: I'm new to this project (like 1 hour), so please forgive my ignorance. I drilled down into dump() to try to isolate the problem to either the parser or the formatting. For this problem case, the underlying data is:
It seems to me, that the precision should be 4, not 0. Am I understanding this correctly? |
Never mind, after looking through the lexer, I realized precision isn't sig figs, but number-of-figs-after-radix in this context. In which case, 2342e-2 is being lexed and parsed correctly, so I'll look back into the dump formatting again. |
Since we're using snprintf with "%.*e" to generate the string, wouldn't we want 2342e-2 to dump as 2.342e01? (since it is going to print one leading digit for scientific notation) If I detect this particular case, and pack the buffer with precision=3, I can get the test to pass. My spidey sense tells me that we might need a little more logic in the lexer at this point:
This logic works fine for test cases like 10e3. They actually only have 1 significant figure anyway, so the precision can be set to 0. |
Ok, I have a working fix. It passes all the old tests, and now we get 2.342e01 instead of 2e01. I need to clean up my patch before submitting it, but it's getting late (1:30am here), so I'll do that tomorrow. |
Thanks for looking at the issue @KAMTRON! I am looking forward to the fix. Good night! :) |
I have a dumb question @nlohmann . How do I
in order to generate json.hpp? I don't see that target in the makefile anywhere. I have built re2c and run it on json.hpp.re2c, but that gives me the lexer with all the gotos. I feel like I'm missing something really simple. |
running
The Makefile has If it still does not work, please let me know. |
@nlohmann Thanks. I never did get it to work with make, but I could get by running the command manually. |
Hey guys, any news about the patch? |
I'll check tonight. |
I had a look at #240. I still see the following issue: Some numbers ( In the current state, I am unhappy with this behavior and - as a last resort - I would tend to reverse #201 and not to take any effort into preserving the format of parsed numbers as this is neither demanded by the JSON standard nor can it be realized with less code than a simple transformation of strings to numbers. I would be happy to discuss this issue, but I do not want to merge #240 in the current state. |
@twelsby It would be great if you could have a look at this issue. |
Sorry I haven't gotten back to this thread in a while, it's been a busy few weeks. Anyhow, to bring @twelsby and anyone else up to speed, here's the core of the issue: Say we have the following metadata saved about an input decimal number:
There are multiple ways this could be represented as a string, so we are inherently sunk. I put a fix into the parser to correctly set the precision to 4, so we would at least get the right value (before it was truncated), but there isn't enough information to reconstruct the original string (my fix just defaults to scientific notation). We can
I would tend to lean towards option 1, but I'm new to the project and I don't want to rock the boat :-) |
Also, a big thanks to @nlohmann for helping me get up to speed on the project! |
@KAMTRON Thanks for coming back on this. I currently also tend to reverse #201. As much as I like the idea of having nice roundtrip behavior, the costs for this become more and more apparent. Since nothing is lost due to versioning, I could move the issue to the long-term whishlist for the library to have it looked at after the 2.0.0 release. |
I opened a feature branch to remove the roundtripping support for floating-point numbers. The code compiles and passes the adjusted test suite, but I have not checked with #201 whether I can remove more code. I tend to pull this into the develop branch and prepare the 2.0.0 release soon. |
Merged branch https://github.com/nlohmann/json/tree/feature/undo-number-roundtrip. Number roundtripping support has been removed. The feature may be added again in the future, but the current implementation had too many subtle flaws. |
The new floating point representation (#201) has a bug when it comes to negative exponents. Number
2342e-2
is correctly duped as23.42
, but when it is parsed from a string, the output is2e01
.Example code:
Output:
@twelsby Any idea about this?
The text was updated successfully, but these errors were encountered: