diff --git a/docs/content/manual/dev/manual.yml b/docs/content/manual/dev/manual.yml index 27ab1fc8..70120e33 100644 --- a/docs/content/manual/dev/manual.yml +++ b/docs/content/manual/dev/manual.yml @@ -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. diff --git a/jq.1.prebuilt b/jq.1.prebuilt index 2c47856b..deed57d5 100644 --- a/jq.1.prebuilt +++ b/jq.1.prebuilt @@ -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\. diff --git a/src/builtin.jq b/src/builtin.jq index d6ae891c..f5b53c55 100644 --- a/src/builtin.jq +++ b/src/builtin.jq @@ -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"); diff --git a/tests/jq.test b/tests/jq.test index 06ef7f63..333e326c 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -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