Repository navigation
Conversation
itchyny
reviewed
Nov 22, 2026
| - gojq is purely implemented with Go language and is completely portable. jq depends on the C standard library so the availability of math functions depends on the library. jq also depends on the regular expression library and it makes build scripts complex. | ||
| - gojq does not keep the order of object keys. I understand this might cause problems for some scripts but basically, we should not rely on the order of object keys. Due to this limitation, gojq does not have `keys_unsorted` function and `--sort-keys` (`-S`) option. I would implement when ordered map is implemented in the standard library of Go but I'm less motivated. | ||
| - gojq supports arbitrary-precision integer calculation while jq does not; jq loses the precision of large integers when calculation is involved. Note that even with gojq, all mathematical functions, including `floor` and `round`, convert integers to floating-point numbers; only addition, subtraction, multiplication, modulo, and division operators (when divisible) keep the integer precision. To calculate floor division of integers without losing the precision, use `def idivide($n): (. - . % $n) / $n;`. To round down floating-point numbers to integers, use `def ifloor: floor | tostring | tonumber;`, but note that this function does not work with large floating-point numbers and also loses the precision of large integers. | ||
| - gojq supports arbitrary-precision integer calculation while jq does not; jq loses the precision of large integers when calculation is involved. Note that even with gojq, all mathematical functions, including `floor` and `round`, convert integers to floating-point numbers; only addition, subtraction, multiplication, modulo, and division operators (when divisible) keep the integer precision. To calculate floor division of integers without losing precision, use `def idivide($n): (. % $n) as $r | (. - $r) / $n - (if $r * $n < 0 then 1 else 0 end);` (for example, `-5 | idivide(2)` returns `-3`). To round down floating-point numbers to integers, use `def ifloor: floor | tostring | tonumber;`, but note that this function does not work with large floating-point numbers and also loses the precision of large integers. |
Owner
There was a problem hiding this comment.
I don't like sudden for example sentence here. Also, def idivide($n): (. - (. % $n + $n) % $n) / $n; is a simpler definition I'd like to take. Honestly I'd like to leave users to define a function like this (I'd like rather dropping), but it's okay fixing for now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The README calls the
idivideexample floor division, but subtracting the remainder only truncates the quotient toward zero. The original example returns-2for-5 / 2; floor division should return-3.Subtract one more when the nonzero remainder and divisor have opposite signs. The division itself remains exact, so the example still works for integers larger than a float can represent. This is a README-only change.
Validation on Go 1.26.0 (macOS arm64): the exact documented query matched integer floor division across 882 cases, including both divisor signs, zero numerators, exact divisibility, and 127-bit values.
go test -mod=readonly -p 2 -count=1 ./...andgit diff --checkpassed.AI assistance was used to prepare and verify this documentation change.