Save literal value of the parsed number to preserve it for the output

Extend jv_number to use decNumber for storing number literals. Any math
operations on the numbers will truncate them to double precision.
Comparisons when both numbers are literal numbers will compare them
without truncation.

Delay conversion of numbers to doubles until a math operation is performed,
to preserve precision. A literal jv_number will only need conversion to
double once, and will reuse the resultant double on subsequent
conversions.

Outputting literal jv_numbers preserves the original precision.

Add strong pthread requirement to manage contexts/allocations for
converting numbers between their decNumber, string, and double formats.
This commit is contained in:
Leonid S. Usov authored and William Langford committed 2019-10-22 14:11:04 -04:00
1 parent b6be13d5de
commit cf4b48c7ba
21 files changed
+1374 -755

No files matched your search

+39
View File
@@ -1673,3 +1673,42 @@ false
#null
#
# Tests to cover the new toliteral number functionality
# For an example see #1652 and other linked issues
#
# We are backward and sanity compatible
map(. == 1)
[1, 1.0, 1.000, 100e-2, 1e+0, 0.0001e4]
[true, true, true, true, true, true]
# When no arithmetic is involved jq should preserve the literal value
.[0] | tostring
[13911860366432393]
"13911860366432393"
.x | tojson
{"x":13911860366432393}
"13911860366432393"
13911860366432393 == 13911860366432392
null
false
# Applying arithmetic to the value will truncate the result to double
. - 10
13911860366432393
13911860366432382
.[0] - 10
[13911860366432393]
13911860366432382
.x - 10
{"x":13911860366432393}
13911860366432382
+14
View File
@@ -0,0 +1,14 @@
{
macos valgrind 1
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
fun:map_images_nolock
...
fun:_dyld_objc_notify_register
fun:_objc_init
fun:_os_object_init
fun:libdispatch_init
fun:libSystem_initializer
...
}
+2 -1
View File
@@ -14,7 +14,8 @@ JQ=$JQBASEDIR/jq
if [ -z "${NO_VALGRIND-}" ] && which valgrind > /dev/null; then
VALGRIND="valgrind --error-exitcode=1 --leak-check=full \
--suppressions=$JQTESTDIR/onig.supp"
--suppressions=$JQTESTDIR/onig.supp \
--suppressions=$JQTESTDIR/local.supp"
VG_EXIT0=--error-exitcode=0
Q=-q
else