Make tests pass when --disable-decnum
This commit is contained in:
1 parent
c1276169d6
commit
6d02d53f51
8 files changed
+88
-37
No files matched your search
@@ -357,10 +357,13 @@ sections:
|
||||
|
||||
The way in which jq handles numbers has changed over time
|
||||
and further changes are likely within the parameters set by
|
||||
the relevant JSON standards. The following remarks are
|
||||
therefore offered with the understanding that they are
|
||||
intended to be descriptive of the current version of jq and
|
||||
should not be interpreted as being prescriptive:
|
||||
the relevant JSON standards. Moreover, build configuration
|
||||
options can alter how jq processes numbers.
|
||||
|
||||
The following remarks are therefore offered with the
|
||||
understanding that they are intended to be descriptive of the
|
||||
current version of jq and should not be interpreted as being
|
||||
prescriptive:
|
||||
|
||||
(1) Any arithmetic operation on a number that has not
|
||||
already been converted to an IEEE754 double precision
|
||||
@@ -368,9 +371,10 @@ sections:
|
||||
representation.
|
||||
|
||||
(2) jq will attempt to maintain the original decimal
|
||||
precision of number literals, but in expressions such
|
||||
`1E1234567890`, precision will be lost if the exponent is
|
||||
too large.
|
||||
precision of number literals (if the `--disable-decnum`
|
||||
build configuration option was not used), but in expressions
|
||||
such `1E1234567890`, precision will be lost if the exponent
|
||||
is too large.
|
||||
|
||||
(3) In jq programs, a leading minus sign will trigger the
|
||||
conversion of the number to an IEEE754 representation.
|
||||
@@ -379,6 +383,12 @@ sections:
|
||||
big decimal representation of numbers if available, as
|
||||
illustrated in one of the following examples.
|
||||
|
||||
The examples below use the builtin function `have_decnum` in
|
||||
order to demonstrate the expected effects of using / not
|
||||
using the `--disable-decnum` build configuration option, and
|
||||
also to allow automated tests derived from these examples to
|
||||
pass regardless of whether that option is used.
|
||||
|
||||
examples:
|
||||
- program: '.'
|
||||
input: '"Hello, world!"'
|
||||
@@ -388,21 +398,21 @@ sections:
|
||||
input: '0.12345678901234567890123456789'
|
||||
output: ['0.12345678901234567890123456789']
|
||||
|
||||
- program: '[., tojson]'
|
||||
- program: '[., tojson] | . == if have_decnum then [12345678909876543212345,"12345678909876543212345"] else [12345678909876543000000,"12345678909876543000000"] end'
|
||||
input: '12345678909876543212345'
|
||||
output: ['[12345678909876543212345,"12345678909876543212345"]']
|
||||
output: ['true']
|
||||
|
||||
- program: '. < 0.12345678901234567890123456788'
|
||||
input: '0.12345678901234567890123456789'
|
||||
output: ['false']
|
||||
|
||||
- program: 'map([., . == 1]) | tojson'
|
||||
- program: 'map([., . == 1]) | tojson | . == if have_decnum then "[[1,true],[1.000,true],[1.0,true],[1.00,true]]" else "[[1,true],[1,true],[1,true],[1,true]]" end'
|
||||
input: '[1, 1.000, 1.0, 100e-2]'
|
||||
output: ['"[[1,true],[1.000,true],[1.0,true],[1.00,true]]"']
|
||||
output: ['true']
|
||||
|
||||
- program: '. as $big | [$big, $big + 1] | map(. > 10000000000000000000000000000000)'
|
||||
- program: '. as $big | [$big, $big + 1] | map(. > 10000000000000000000000000000000) | . == if have_decnum then [true, false] else [false, false] end'
|
||||
input: '10000000000000000000000000000001'
|
||||
output: ['[true, false]']
|
||||
output: ['true']
|
||||
|
||||
- title: "Object Identifier-Index: `.foo`, `.foo.bar`"
|
||||
body: |
|
||||
@@ -1992,6 +2002,19 @@ sections:
|
||||
output:
|
||||
- '[{"a":{"b":2}}]'
|
||||
|
||||
- title: "`have_literal_numbers`"
|
||||
body: |
|
||||
|
||||
This builtin returns true if jq's build configuration
|
||||
includes support for preservation of input number literals.
|
||||
|
||||
- title: "`have_decnum`"
|
||||
body: |
|
||||
|
||||
This builtin returns true if jq was built with "decnum",
|
||||
which is the current literal number preserving numeric
|
||||
backend implementation for jq.
|
||||
|
||||
- title: "`$JQ_BUILD_CONFIGURATION`"
|
||||
body: |
|
||||
|
||||
|
||||
Reference in new issue
Block a user