manual.yml: revise section on identity, clarifying what is subject to change
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Mostly clarifications w.r.t. numbers. The anomalous behavior of leading minus signs is documented, with an explicit notice that this will probably change.
authored by pkoppstein · committed by Nico Williams · parent a192e64 · Browse files · 3 files·+95 added−27 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+95 added−27 removed
- tests:+10 added−2 removed
- other:+85 added−25 removed
Provenance
- Commit
3ec66c8- Tree
db6dd04- Author
pkoppstein <pkoppstein@gmail.com>- Committer
Nico Williams <nico@cryptonector.com>- Parent
a192e64
3 files changed+95 added−27 removed
modified:docs/content/manual/manual.yml+48 added-18 removed
310 unmodified lines311 entries:312 - title: "Identity: `.`"313 body: |314 315- The absolute simplest filter is `.` . This is a filter that316- takes its input and produces it unchanged as output. That is,317- this is the identity operator.315+ The absolute simplest filter is `.` . This filter takes its316+ input and produces the same value as output. That is, this317+ is the identity operator.318 319- Since jq by default pretty-prints all output, this trivial320- program can be a useful way of formatting JSON output from,321- say, `curl`.319+ Since jq by default pretty-prints all output, a trivial320+ program consisting of nothing but `.` can be used to format321+ JSON output from, say, `curl`.322 323- An important point about the identity filter is that it324- guarantees to preserve the literal decimal representation325- of values. This is particularly important when dealing with numbers326- which can't be losslessly converted to an IEEE754 double precision323+ Although the identity filter never modifies the value of its324+ input, jq processing can sometimes make it appear as though325+ it does. For example, using the current implementation of326+ jq, we would see that the expression:327+ 328+ `1E1234567890 | .`329+330+ produces `1.7976931348623157e+308` on at least one platform.331+ This is because, in the process of parsing the number, this332+ particular version of jq has converted it to an IEEE754333+ double-precision representation, losing precision.334+335+ The way in which jq handles numbers has changed over time336+ and further changes are likely within the parameters set by337+ the relevant JSON standards. The following remarks are338+ therefore offered with the understanding that they are339+ intended to be descriptive of the current version of jq and340+ should not be interpreted as being prescriptive:341+342+ (1) Any arithmetic operation on a number that has not343+ already been converted to an IEEE754 double precision344+ representation will trigger a conversion to the IEEE754345 representation.346 329- jq doesn't truncate the literal numbers to double unless there330- is a need to make arithmetic operations with the number.331- Comparisons are carried out over the untruncated big decimal332- representation of the number.347+ (2) jq will attempt to maintain the original decimal348+ precision of number literals, but in expressions such349+ `1E1234567890`, precision will be lost if the exponent is350+ too large.351 334- jq will also try to maintain the original decimal precision of the provided335- number literal. See below for examples.352+ (3) In jq programs, a leading minus sign will trigger the353+ conversion of the number to an IEEE754 representation.354 355+ (4) Comparisons are carried out using the untruncated356+ big decimal representation of numbers if available, as357+ illustrated in one of the following examples.358+359 examples:360 - program: '.'361 input: '"Hello, world!"'362 output: ['"Hello, world!"']363 342- - program: '. | tojson'364+ - program: '.'365+ input: '0.12345678901234567890123456789'366+ output: ['0.12345678901234567890123456789']367+368+ - program: '[., tojson]'369 input: '12345678909876543212345'344- output: ['"12345678909876543212345"']370+ output: ['[12345678909876543212345,"12345678909876543212345"]']371 372+ - program: '. < 0.12345678901234567890123456788'373+ input: '0.12345678901234567890123456789'374+ output: ['false']375+376 - program: 'map([., . == 1]) | tojson'377 input: '[1, 1.000, 1.0, 100e-2]'378 output: ['"[[1,true],[1.000,true],[1.0,true],[1.00,true]]"']379 3166 unmodified linesmodified:tests/man.test+10 added-2 removed
1 .2 "Hello, world!"3 "Hello, world!"4 5-. | tojson5+.6+0.123456789012345678901234567897+0.123456789012345678901234567898+9+[., tojson]10 123456789098765432123457-"12345678909876543212345"11+[12345678909876543212345,"12345678909876543212345"]12 13+. < 0.1234567890123456789012345678814+0.1234567890123456789012345678915+false16+17 map([., . == 1]) | tojson18 [1, 1.000, 1.0, 100e-2]19 "[[1,true],[1.000,true],[1.0,true],[1.00,true]]"20 854 unmodified linesmodified:jq.1.prebuilt+37 added-7 removed
244 unmodified lines245 .246 .SH "BASIC FILTERS"247 .248 .SS "Identity: \."249-The absolute simplest filter is \fB\.\fR \. This is a filter that takes its input and produces it unchanged as output\. That is, this is the identity operator\.249+The absolute simplest filter is \fB\.\fR \. This filter takes its input and produces the same value as output\. That is, this is the identity operator\.250 .251 .P252-Since jq by default pretty\-prints all output, this trivial program can be a useful way of formatting JSON output from, say, \fBcurl\fR\.252+Since jq by default pretty\-prints all output, a trivial program consisting of nothing but \fB\.\fR can be used to format JSON output from, say, \fBcurl\fR\.253 .254 .P255-An important point about the identity filter is that it guarantees to preserve the literal decimal representation of values\. This is particularly important when dealing with numbers which can\'t be losslessly converted to an IEEE754 double precision representation\.255+Although the identity filter never modifies the value of its input, jq processing can sometimes make it appear as though it does\. For example, using the current implementation of jq, we would see that the expression:256 .257+.IP "" 4258+.259+.nf260+261+`1E1234567890 | \.`262+.263+.fi264+.265+.IP "" 0266+.267 .P258-jq doesn\'t truncate the literal numbers to double unless there is a need to make arithmetic operations with the number\. Comparisons are carried out over the untruncated big decimal representation of the number\.268+produces \fB1\.7976931348623157e+308\fR on at least one platform\. This is because, in the process of parsing the number, this particular version of jq has converted it to an IEEE754 double\-precision representation, losing precision\.269 .270 .P261-jq will also try to maintain the original decimal precision of the provided number literal\. See below for examples\.271+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:272 .273+.P274+(1) Any arithmetic operation on a number that has not already been converted to an IEEE754 double precision representation will trigger a conversion to the IEEE754 representation\.275+.276+.P277+(2) jq will attempt to maintain the original decimal precision of number literals, but in expressions such \fB1E1234567890\fR, precision will be lost if the exponent is too large\.278+.279+.P280+(3) In jq programs, a leading minus sign will trigger the conversion of the number to an IEEE754 representation\.281+.282+.P283+(4) Comparisons are carried out using the untruncated big decimal representation of numbers if available, as illustrated in one of the following examples\.284+.285 .IP "" 4286 .287 .nf288 289 jq \'\.\'290 "Hello, world!"291 => "Hello, world!"292 271-jq \'\. | tojson\'293+jq \'\.\'294+ 0\.12345678901234567890123456789295+=> 0\.12345678901234567890123456789296+297+jq \'[\., tojson]\'298 12345678909876543212345273-=> "12345678909876543212345"299+=> [12345678909876543212345,"12345678909876543212345"]300 301+jq \'\. < 0\.12345678901234567890123456788\'302+ 0\.12345678901234567890123456789303+=> false304+305 jq \'map([\., \. == 1]) | tojson\'306 [1, 1\.000, 1\.0, 100e\-2]307 => "[[1,true],[1\.000,true],[1\.0,true],[1\.00,true]]"308 3636 unmodified lines