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

fix: preserve numerical precision on unary negation #3242

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

itchyny
Copy link
Contributor

@itchyny itchyny commented Jan 30, 2025

This commit fixes #2704.

 $ ./jq -n '[1234567890987654321,-1234567890987654321 | tojson]'
[
  "1234567890987654321",
  "-1234567890987654321"
]

@itchyny itchyny added the bug label Jan 30, 2025
@itchyny itchyny added this to the 1.8 release milestone Jan 30, 2025
@itchyny itchyny force-pushed the unary-negation-preserve-precision branch from 14eb4a8 to ed38840 Compare January 30, 2025 12:00
@itchyny itchyny changed the title fix: preserve numerical precision on unary negation (fix #2704) fix: preserve numerical precision on unary negation Jan 30, 2025
@itchyny itchyny force-pushed the unary-negation-preserve-precision branch 3 times, most recently from 20a5e0a to 1e58b2f Compare February 2, 2025 15:55
@@ -571,19 +570,18 @@ static jvp_literal_number* jvp_literal_number_alloc(unsigned literal_length) {
+ sizeof(decNumberUnit) * units
);

n->refcnt = JV_REFCNT_INIT;
n->num_double = NAN;
n->literal_data = NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reson to move this from new to alloc?

Looks like jvp_literal_number_new is the only user of jvp_literal_number_alloc, maybe could be merged or keep separate for readability?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also used for negate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha sorry 👍

@wader
Copy link
Member

wader commented Feb 3, 2025

Nice! have some vague memory of trying to fix this just for constant literals by changing the lexer to include the - in the literal but got messy for some reason

@itchyny
Copy link
Contributor Author

itchyny commented Feb 5, 2025

Thank you!

@itchyny itchyny merged commit 6ce3bdf into jqlang:master Feb 5, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: preservation of literal numbers
2 participants