1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Fix #814: raise on div-0, add inf isinf nan isnan

This commit is contained in:
Nicolas Williams
2015-06-17 19:46:57 -05:00
parent bdc1feb50e
commit b9c2a326ba
8 changed files with 477 additions and 388 deletions

View File

@@ -598,7 +598,7 @@ sections:
that string that many times.
Dividing a string by another splits the first using the second
as separators.
as separators. Division by zero raises an error.
Multiplying two objects will merge them recursively: this works
like addition but if both objects contain a value for the
@@ -615,6 +615,9 @@ sections:
- program: '{"k": {"a": 1, "b": 2}} * {"k": {"a": 0,"c": 3}}'
input: 'null'
output: ['{"k": {"a": 0, "b": 2, "c": 3}}']
- program: '.[] | (1 / .)?'
input: '[1,0,-1]'
output: ['1', '-1']
- title: "`length`"
@@ -1073,6 +1076,25 @@ sections:
input: '[0, false, [], {}, null, "hello"]'
output: ['["number", "boolean", "array", "object", "null", "string"]']
- title: "`inf`, `nan`, `isinf`, `isnan`"
body: |
Some arithmetic operations can yield infinities and "not a
number" (NaN) values. The `isinf` builtin returns `true` if
its input is infinite. The `isnan` builtin returns `true` if
its input is a NaN. The `inf` builtin returns a positive
infinite value. The `nan` builtin returns a NaN.
Note that division by zero raises an error.
examples:
- program: '.[] | (inf * .) < 0'
input: '[-1, 1]'
output: ['true', 'false']
- program: 'inf, nan | type'
input: 'null'
output: ['"number"']
- title: "`sort, sort_by(path_expression)`"
body: |