Fix isfinite to return false for NaN (#3510)
`isfinite` checked only for infinities, so `nan | isfinite` was true and `finites` let NaN through. A finite number is neither infinite nor NaN, as in C's `isfinite`, `Number.isFinite` and `math.isfinite`.
This commit is contained in:
4 files changed
+17
-4
No files matched your search
@@ -1523,8 +1523,9 @@ sections:
|
||||
if its input is infinite. The `isnan` builtin returns `true`
|
||||
if its input is a NaN. The `infinite` builtin returns a
|
||||
positive infinite value. The `nan` builtin returns a NaN.
|
||||
The `isnormal` builtin returns true if its input is a normal
|
||||
number.
|
||||
The `isfinite` builtin returns `true` if its input is a number
|
||||
that is neither infinite nor a NaN. The `isnormal` builtin
|
||||
returns true if its input is a normal number.
|
||||
|
||||
Note that division by zero raises an error.
|
||||
|
||||
|
||||
Generated
+1
-1
@@ -1630,7 +1630,7 @@ jq \'map(type)\'
|
||||
.IP "" 0
|
||||
.
|
||||
.SS "infinite, nan, isinfinite, isnan, isfinite, isnormal"
|
||||
Some arithmetic operations can yield infinities and "not a number" (NaN) values\. The \fBisinfinite\fR builtin returns \fBtrue\fR if its input is infinite\. The \fBisnan\fR builtin returns \fBtrue\fR if its input is a NaN\. The \fBinfinite\fR builtin returns a positive infinite value\. The \fBnan\fR builtin returns a NaN\. The \fBisnormal\fR builtin returns true if its input is a normal number\.
|
||||
Some arithmetic operations can yield infinities and "not a number" (NaN) values\. The \fBisinfinite\fR builtin returns \fBtrue\fR if its input is infinite\. The \fBisnan\fR builtin returns \fBtrue\fR if its input is a NaN\. The \fBinfinite\fR builtin returns a positive infinite value\. The \fBnan\fR builtin returns a NaN\. The \fBisfinite\fR builtin returns \fBtrue\fR if its input is a number that is neither infinite nor a NaN\. The \fBisnormal\fR builtin returns true if its input is a normal number\.
|
||||
.
|
||||
.P
|
||||
Note that division by zero raises an error\.
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ def index($i): indices($i) | .[0]; # TODO: optimize
|
||||
def rindex($i): indices($i) | .[-1:][0]; # TODO: optimize
|
||||
def paths: path(recurse)|select(length > 0);
|
||||
def paths(node_filter): path(recurse|select(node_filter))|select(length > 0);
|
||||
def isfinite: type == "number" and (isinfinite | not);
|
||||
def isfinite: type == "number" and (isinfinite | not) and (isnan | not);
|
||||
def arrays: select(type == "array");
|
||||
def objects: select(type == "object");
|
||||
def iterables: select(type|. == "array" or . == "object");
|
||||
|
||||
@@ -726,6 +726,18 @@ null
|
||||
null
|
||||
[true,true]
|
||||
|
||||
nan|isfinite
|
||||
null
|
||||
false
|
||||
|
||||
[0, 1, nan, infinite, -infinite] | map(isfinite)
|
||||
null
|
||||
[true, true, false, false, false]
|
||||
|
||||
[0, 1, nan, infinite, -infinite] | [.[] | finites]
|
||||
null
|
||||
[0, 1]
|
||||
|
||||
1 + tonumber + ("10" | tonumber)
|
||||
4
|
||||
15
|
||||
|
||||
Reference in new issue
Block a user