Make 0 divided by 0 results in NaN consistently (#2253)
This commit is contained in:
1 parent
dfd440f0de
commit
886a9b18b1
2 files changed
+6
-1
No files matched your search
+1
-1
@@ -381,7 +381,7 @@ static jv f_multiply(jq_state *jq, jv input, jv a, jv b) {
|
|||||||
static jv f_divide(jq_state *jq, jv input, jv a, jv b) {
|
static jv f_divide(jq_state *jq, jv input, jv a, jv b) {
|
||||||
jv_free(input);
|
jv_free(input);
|
||||||
if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
|
if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
|
||||||
if (jv_number_value(b) == 0.0)
|
if (jv_number_value(b) == 0.0 && jv_number_value(a) != 0.0)
|
||||||
return type_error2(a, b, "cannot be divided because the divisor is zero");
|
return type_error2(a, b, "cannot be divided because the divisor is zero");
|
||||||
jv r = jv_number(jv_number_value(a) / jv_number_value(b));
|
jv r = jv_number(jv_number_value(a) / jv_number_value(b));
|
||||||
jv_free(a);
|
jv_free(a);
|
||||||
|
|||||||
@@ -1578,6 +1578,11 @@ try (1/.) catch .
|
|||||||
0
|
0
|
||||||
"number (1) and number (0) cannot be divided because the divisor is zero"
|
"number (1) and number (0) cannot be divided because the divisor is zero"
|
||||||
|
|
||||||
|
0/0, (0 as $x | $x/0) | isnan
|
||||||
|
0
|
||||||
|
true
|
||||||
|
true
|
||||||
|
|
||||||
try (1%.) catch .
|
try (1%.) catch .
|
||||||
0
|
0
|
||||||
"number (1) and number (0) cannot be divided (remainder) because the divisor is zero"
|
"number (1) and number (0) cannot be divided (remainder) because the divisor is zero"
|
||||||
|
|||||||
Reference in new issue
Block a user