The double-to-text conversion renders infinity as 9e999, so that JSON

output is compliant and so that values can be round-tripped.

FossilOrigin-Name: b52081d0acd07dc5bdb4951a3e8419866131965260c1e3a4c9b6e673bfe3dfea
This commit is contained in:
drh 2023-03-22 16:24:17 +00:00
commit c408c155d7
5 changed files with 36 additions and 15 deletions

View File

@ -1,5 +1,5 @@
C In\sthe\sCLI,\sthe\smagic\sparameter\s:inf\sand\s:nan\sbind\sfloating\spoint\svalues\nInfinity\sand\sNaN,\srespectively,\sas\san\sadd\sto\stesting\sSQLite's\shandling\sof\nthose\squantities.
D 2023-03-22T16:01:06.778
C The\sdouble-to-text\sconversion\srenders\sinfinity\sas\s9e999,\sso\sthat\sJSON\noutput\sis\scompliant\sand\sso\sthat\svalues\scan\sbe\sround-tripped.
D 2023-03-22T16:24:17.609
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -585,7 +585,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
F src/hwtime.h b638809e083b601b618df877b2e89cb87c2a47a01f4def10be4c4ebb54664ac7
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c 7940fce7d4aa855606432d82d20694e17c18a03956f5f5776f2404e2df7c18a8
F src/json.c c85ed6fce06f43d414b0d7fff64749d43a0dbd1067123ee407bd3a0752454161
F src/json.c 9e3a6acf9e4fa8bb6c84a38538ed9c2f9ad09f106910ef0e9cc68e19c8dc4fc8
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c b04eb648cedc45efe4298e1ef439ac4f0096ae27b5f01accb0a1f49d57789128
F src/main.c 09bc5191f75dc48fc4dfddda143cb864c0c3dbc3297eb9a9c8e01fea58ff847d
@ -621,7 +621,7 @@ F src/pcache1.c dee95e3cd2b61e6512dc814c5ab76d5eb36f0bfc9441dbb4260fccc0d12bbddc
F src/pragma.c c0c6e0735436e0e9e8d490f82959ddc9475d438e9f808a51953a4d43e30cea51
F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7
F src/prepare.c ce87a08cfddd45a147150db34190b1986f2d4a0e0828858cb6bd908c78fb02e3
F src/printf.c fb31597cf93200eba9167573094ee312b0d51b2c1998613284ceb2c8c212b492
F src/printf.c 8c16d3783e87d5899c23a2736106dca11645b50e2c8606766d2d1446de278a0c
F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c 3e53e02ce87c9582bd7e7d22f13f4094a271678d9dc72820fa257a2abb5e4032
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
@ -1241,7 +1241,7 @@ F test/journal3.test 7c3cf23ffc77db06601c1fcfc9743de8441cb77db9d1aa931863d94f5ff
F test/jrnlmode.test 9b5bc01dac22223cb60ec2d5f97acf568d73820794386de5634dcadbea9e1946
F test/jrnlmode2.test 8759a1d4657c064637f8b079592651530db738419e1d649c6df7048cd724363d
F test/jrnlmode3.test 556b447a05be0e0963f4311e95ab1632b11c9eaa
F test/json101.test 9f6337e7423d2c1774d1d485c919fc4e11c8f7e423a2f8831f73471983432108
F test/json101.test c7707ee623c57a24845ef260d4388a6fade1eb294e450caadd7f1d9ced19dea7
F test/json102.test 327e77275f338c028faefa2da5164daf6b142a165e3015ff2a6e4251ddc6a0ac
F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a8880112dbe
F test/json104.test a502dc01853aada95d721b3b275afbe2dc18fffdac1fea6e96fb20c13586bbb5
@ -2051,8 +2051,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 03e6918e7f749c3ca1fa66df28b203ff26680f129003e20c71ca246cf7ff34fe
R 8e977335e4f9dd507a1a79512cd70e26
P c70a61d8fbfb722679398c211aa48ccd84a392a6b59ba70551fe3a9fbab9a6d5 efce4690a52592c4f5fc7d023eebe771b0e615bb03c0fe203493f853b28e8f85
R 877d544aec0d825a0fa74ee8dc5a48fd
T +closed efce4690a52592c4f5fc7d023eebe771b0e615bb03c0fe203493f853b28e8f85
U drh
Z e01204911fdf00ed5178cd1186ef489a
Z e50ed26df279ddaf1f9de438f8e2a2a0
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
c70a61d8fbfb722679398c211aa48ccd84a392a6b59ba70551fe3a9fbab9a6d5
b52081d0acd07dc5bdb4951a3e8419866131965260c1e3a4c9b6e673bfe3dfea

View File

@ -307,8 +307,11 @@ static void jsonAppendValue(
jsonAppendRaw(p, "null", 4);
break;
}
case SQLITE_INTEGER:
case SQLITE_FLOAT: {
jsonPrintf(100, p, "%!0.15g", sqlite3_value_double(pValue));
break;
}
case SQLITE_INTEGER: {
const char *z = (const char*)sqlite3_value_text(pValue);
u32 n = (u32)sqlite3_value_bytes(pValue);
jsonAppendRaw(p, z, n);

View File

@ -601,11 +601,16 @@ void sqlite3_str_vappendf(
while( realvalue<1e-8 ){ realvalue *= 1e8; exp-=8; }
while( realvalue<1.0 ){ realvalue *= 10.0; exp--; }
if( exp>350 ){
bufpt = buf;
buf[0] = prefix;
memcpy(buf+(prefix!=0),"Inf",4);
length = 3+(prefix!=0);
break;
if( flag_zeropad ){
realvalue = 9.0;
exp = 999;
}else{
bufpt = buf;
buf[0] = prefix;
memcpy(buf+(prefix!=0),"Inf",4);
length = 3+(prefix!=0);
break;
}
}
if( xtype!=etFLOAT ){
realvalue += rounder;

View File

@ -885,4 +885,16 @@ do_execsql_test json-19.3 {
SELECT * FROM t1;
} {}
# 2023-03-17 positive and negative infinities
#
do_execsql_test json-20.1 {
SELECT json_object('a',2e370,'b',-3e380);
} {{{"a":9.0e+999,"b":-9.0e+999}}}
do_execsql_test json-20.2 {
SELECT json_object('a',2e370,'b',-3e380)->>'a';
} Inf
do_execsql_test json-20.3 {
SELECT json_object('a',2e370,'b',-3e380)->>'b';
} {-Inf}
finish_test