-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Negative infinity round-trips as invalid JSON #1405
Comments
I'm a little stuck on this one. The description says: "inf and -inf don't round trip if useSpecialFloats is false."
What do you mean by incorrect there? So it's hard to know what your expectation is. You have formatted a -infinity without special floats, so you are essentially formatting an unrepresentable number. There's no right answer available to jsoncpp here. Expected behavior: "Should at least parse rather than hard fail." What value would you expect the parse to produce? The -infinity isn't recoverable because that's not what's in the json. |
I eventually realized that I was using the builder that didn't allow options on the reading, so I ended up fixing that part - I can read/write inf & -inf with that enabled and all is well in my use-case. I think there's still an issue, though; if you write an inf out, it writes a value that it then can't read back. I know it's technically not the same value as inf, but I'd expect the library to still be able to read back in something it wrote instead of throwing a hard failure that you can't ignore (none of the options allow you to 'read around' this bad value). That's the part that seems like a bug or unintended behavior. I think people would prefer it error on writing, so that they can catch this as it's going out, rather than having a value in the written JSON that the reader can't read (if you're not reading the JSON back in immediately and instead saving for later, you wouldn't know this timebomb was waiting until you got to reading it, and it's not immediately clear where |
I agree with everything you're saying. I would prefer that it error out on writing. |
Describe the bug
inf and -inf don't round trip if useSpecialFloats is false.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Should at least parse rather than hard fail.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: