-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
bug: preservation of literal numbers #2704
Comments
I believe the issue is that it parses the unary |
Correct: ([0-9]+(\.[0-9]*)?|\.[0-9]+)([eE][+-]?[0-9]+)? {
yylval->literal = jv_parse_sized(yytext, yyleng); return LITERAL;
} If this was a JSON text input on
|
I'm not sure how to fix this... I guess we could have |
When |
Not much more than The point is that jq 1.7 will not have infinite-precision integer arithmetic, so while we're in this netherworld, we need to remain quite clear that any arithmetic operation on a number will trigger conversion to IEEE 754 numbers. If the release of a successor to jq 1.6 were not so overdue, there would no doubt be time to come up with something that might be marginally less confusing, but for now, introducing complexities in the name of avoiding confusion just risks increasing it! |
Right, so I don't think this is a bug. Operators convert numbers to floating-numbers regardless of unary or binary. Precision preservation of negation is a part of the feature request for arbitrary-precision integer calculation. |
@itchyny - The point is that whereas "-1" is a JSON number; "- 1" is not. (It's not even JSON, as For jq 1.7, we want JSON numeric literals to be treated specially. Ergo, it's a bug (for jq 1.7). |
Hmm, okay. Let's discuss about how to fix this issue. When |
@itchyny convinces me that fixing this in the lexer is a bad idea. We could fix this in |
Since I opened this issue, I should add that I think it's relatively unimportant, a view that is perhaps supported by the fact that this Issue was not created earlier. That in turn is probably because the preservation of literal numbers is mostly important for non-negative ones, and especially non-negative integers. However, if jq 1.7 does ship with this anomaly, I think it should be documented as something that will probably change, so I've included a sentence to that effect in #2731 |
We are free to change anything we want regarding number representation in JSON emitted by jq as long as we remain compliant with RFC 8259. If we want to replace I understand that IEEE 754 doubles have annoyed people a great deal. Switching to |
Hey all 👋🏼 I don't think I've understood exactly what's the issue here, but when rendering the number ❯ echo 5322917205011726429 | jq
5322917205011726000 I wonder then: would this problem share the same cause as the one originally described in the present issue? |
@GCrispino what jq version is this? please try 1.7 or master which should preserve in your case. Not that this issue is about preserving negative numbers in jq queries which is different from preserving numbers in JSON input |
@wader I was using 1.6. I updated to 1.7 and it worked fine. Sorry for the distraction and thank you for the quick reply! |
OMG that example 🤦🏻 it took me a few minutes to wrap my head around what was happening
Do we really have to preserve this? I think I agree with @pkoppstein that this looks like a defect. A minus in front of a number should be treated as part of the number as long as it follows the rules of how negative numbers can be represented. I haven't yet looked at the lexer/parser side of things, but I presume it should be possible to distinguish between a minus that's part of a number and a minus that represents a binary operation. |
The literal representation of certain negative numbers is not being properly preserved.
Consider:
Platform: Mac OS
The text was updated successfully, but these errors were encountered: