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

Incorrect results when subtracting two long numbers #3007

Closed
dburkat opened this issue Jan 2, 2024 · 2 comments
Closed

Incorrect results when subtracting two long numbers #3007

dburkat opened this issue Jan 2, 2024 · 2 comments

Comments

@dburkat
Copy link

dburkat commented Jan 2, 2024

Describe the bug
A bug when doing the subtraction math operations on long number (e.g. timestamps with nanosecond precision).

To Reproduce

$ echo '{"ts_1": 1701833040235520606, "ts_2": 1701833040235501418}' | jq '{difference: (.ts_1 - .ts_2)}'
{
  "difference": 19200
}

Expected behavior
The expected result is:
1701833040235520606 - 1701833040235501418 = 19188

I noticed that the actual result that we get matches up with:
1701833040235520600 - 1701833040235501400 = 19200
So the timestamps are truncated to the hundredths.

Environment (please complete the following information):

  • macOS (Ventura 13.6.2)
  • jq version 1.7.1

Additional context
I know that jq version 1.7 had a fix to display long numbers correctly. Before version 1.7 the nanoseconds timestamps would get displayed incorrectly . For example 1701833040235501418 would be displayed as 1701833040235501300.

@wader
Copy link
Member

wader commented Jan 3, 2024

Hi, this is expected at the moment and and there is currently no plan on changing it. See #2962 for similar issue. Note that jq 1.7 an 1.7.1 truncates a bit differently. jq 1.7.1 was changed to truncate more similar to other language implementations:

$ node -p '1701833040235520606-1701833040235501418'
19200

If you want to use a jq implementation with big integer operator support you can try https://github.com/itchyny/gojq

@dburkat
Copy link
Author

dburkat commented Jan 3, 2024

Thank you very much for the quick response.

@dburkat dburkat closed this as completed Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants