jaq
jaq copied to clipboard
README.md update re jq's division-by-0 behavior
The paragraph about division by 0 is outdated. Note also that jq's current (1.6) behavior is dependent on whether the numerator is a literal 0 or a variable equal to 0.
$ jq -n '0 as $n | $n / 0'
jq: error (at <unknown>): number (0) and number (0) cannot be divided because the divisor is zero
$ jq -n '1 as $n | $n / 0'
jq: error (at <unknown>): number (1) and number (0) cannot be divided because the divisor is zero
$ jq -n '0 / 0'
null
$ jq -n '1 / 0'
jq: error: Division by zero? at <top-level>, line 1:
1 / 0
jq: 1 compile error
When saying "the paragraph about division by 0", are you talking about the following?
In jaq,
n / 0
yieldsnan
ifn == 0
,infinite
ifn > 0
, and-infinite
ifn < 0
.
I do not see how it is outdated, because I just tried this:
$ jaq -n '0 / 0 | isnan'
true
$ jaq -n '1 / 0 | isinfinite'
true
$ jaq -n '(-1) / 0 | isinfinite'
true
Note also that jq's current (1.6) behavior is dependent on whether the numerator is a literal 0 or a variable equal to 0.
Oh god. Do you have any idea how to describe this behaviour in the README in a concise way?
I was referring to the sentence:
"In jq, n / 0 yields nan (not a number) if n == 0 and fails otherwise"
Perhaps it would suffice to write:
Using jq, the behavior of expressions involving division by 0 varies by version.
If you want to describe jq 1.6, you could point out:
In jq 1.6, '(0/0) | isnan' yields true, but other expressions involving division by 0 yield errors.