From: drh <> Date: Mon, 3 Jul 2023 00:51:03 +0000 (+0000) Subject: The fptest(X) routine used for exploring another idea for improving X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Ffp-to-decimal-branch2;p=thirdparty%2Fsqlite.git The fptest(X) routine used for exploring another idea for improving fp-to-decimal conversion without the use of long double. FossilOrigin-Name: d9a883d7d8f574bd9dfae04cc967d76a9ea8a14140adf406fe51effc03dc4055 --- diff --git a/manifest b/manifest index 60a8a88fd4..c286455fe6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C This\scheck-in\sadds\sthe\suse\sof\s"long\sdouble"\sto\ssqlite3FpDecode()\swhich\swhen\nrun\son\sx86\susing\sa\scompiler\sthat\stranslates\s"long\sdouble"\sinto\sbinary80,\ncauses\sall\slegacy\stests\sto\spass.\s\sBut\son\sa\ssystem\swhere\s"long\sdouble"\sis\sjust\nan\salias\sfor\s"double",\ssome\sof\sthe\stests\sare\sstill\sfailing. -D 2023-07-01T20:21:27.087 +C The\sfptest(X)\sroutine\sused\sfor\sexploring\sanother\sidea\sfor\simproving\nfp-to-decimal\sconversion\swithout\sthe\suse\sof\slong\sdouble. +D 2023-07-03T00:51:03.853 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -590,7 +590,7 @@ F src/delete.c cd5f5cd06ed0b6a882ec1a8c2a0d73b3cecb28479ad19e9931c4706c5e2182be F src/expr.c 8d1656b65e26af3e34f78e947ac423f0d20c214ed25a67486e433bf16ca6b543 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a7fcbf7e66d14dbb73cf49f31489ebf66d0e6006c62b95246924a3bae9f37b36 -F src/func.c 6028c160f693bdd018b651b5468a0a8e790f4e01e200796916b2d10a5d3237aa +F src/func.c 874090385415e6cb779e32875d6d59af74686522de0dcbb04edb58b728d30cf5 F src/global.c bd0892ade7289f6e20bff44c07d06371f2ff9b53cea359e7854b9b72f65adc30 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 @@ -705,7 +705,7 @@ F src/trigger.c ad6ab9452715fa9a8075442e15196022275b414b9141b566af8cdb7a1605f2b0 F src/update.c 0aa36561167a7c40d01163238c297297962f31a15a8d742216b3c37cdf25f731 F src/upsert.c 5303dc6c518fa7d4b280ec65170f465c7a70b7ac2b22491598f6d0b4875b3145 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 -F src/util.c d68692390be083744bd0dfafc797472b0d304743040220e18b93bc9bad8c8d6e +F src/util.c 7e716e44a203218bb708a1f8fc00e48b403bab1c2aace66e5a3c5645ad43a861 F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 F src/vdbe.c 74282a947234513872a83b0bab1b8c644ece64b3e27b053ef17677c8ff9c81e0 F src/vdbe.h 41485521f68e9437fdb7ec4a90f9d86ab294e9bb8281e33b235915e29122cfc0 @@ -2041,8 +2041,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 07eab52e0801bb0e4743b304a06ad16e18cdf8eaa18c0faf8d47a1f5d8576ea0 -R c4051b06b266c29a490b4cec354913fc +P ce06982f880339cf46704e95c907249827c3e44af2b9420005200ca8abd3f371 +R fcd4c85d28a0fc88e052c419e5787fe8 +T *branch * fp-to-decimal-branch2 +T *sym-fp-to-decimal-branch2 * +T -sym-fp-to-decimal-refactor * U drh -Z 95eef79511e3e10371b4b76031a5a06d +Z ed1d700c33c1ea57c968c334c1181eb7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d2f8b9d453..34eea15f52 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ce06982f880339cf46704e95c907249827c3e44af2b9420005200ca8abd3f371 \ No newline at end of file +d9a883d7d8f574bd9dfae04cc967d76a9ea8a14140adf406fe51effc03dc4055 \ No newline at end of file diff --git a/src/func.c b/src/func.c index c6a49de613..09a7892484 100644 --- a/src/func.c +++ b/src/func.c @@ -2373,6 +2373,33 @@ static void signFunc( #ifdef SQLITE_DEBUG /* +** Implementation of fptest(x) function. +*/ +static void fptestFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + double r, r2, r3; + sqlite3_uint64 x; + FpDecode s1, s2; + char zBuf[100]; + + UNUSED_PARAMETER(argc); + r = sqlite3_value_double(argv[0]); + memcpy(&x, &r, 8); + x &= 0xffffffffffff0000LL; + memcpy(&r2, &x, 8); + r3 = r - r2; + + sqlite3FpDecode(&s1, r2, 0, 99); + sqlite3FpDecode(&s2, r3, 0, 99); + sqlite3_snprintf(sizeof(zBuf), zBuf, "%c%.*s/%d+%c%.*s/%d", + s1.sign, s1.n, s1.z, s1.iDP, + s2.sign, s2.n, s2.z, s2.iDP); + sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); +} +/* ** Implementation of fpdecode(x,y,z) function. ** ** x is a real number that is to be decoded. y is the precision. @@ -2474,6 +2501,7 @@ void sqlite3RegisterBuiltinFunctions(void){ FUNCTION(char, -1, 0, 0, charFunc ), FUNCTION(abs, 1, 0, 0, absFunc ), #ifdef SQLITE_DEBUG + FUNCTION(fptest, 1, 0, 0, fptestFunc ), FUNCTION(fpdecode, 3, 0, 0, fpdecodeFunc ), #endif #ifndef SQLITE_OMIT_FLOATING_POINT diff --git a/src/util.c b/src/util.c index a560f26133..aaeaf695da 100644 --- a/src/util.c +++ b/src/util.c @@ -941,7 +941,7 @@ void sqlite3FpDecode(FpDecode *p, double rr, int iRound, int mxRound){ int i; u64 v; int e, exp = 0; - long double r; + double r; p->isSpecial = 0; if( rr<0.0 ){ p->sign = '-'; @@ -971,13 +971,13 @@ void sqlite3FpDecode(FpDecode *p, double rr, int iRound, int mxRound){ ** an unsigned 64-bit integer v, and extract digits from v. */ if( r>=1.0e+19 ){ - while( r>=1.0e+119L ){ exp+=100; r *= 1.0e-100L; } - while( r>=1.0e+29L ){ exp+=10; r *= 1.0e-10L; } - while( r>=1.0e+19L ){ exp++; r *= 1.0e-1L; } + while( r>=1.0e+119 ){ exp+=100; r *= 1.0e-100; } + while( r>=1.0e+29 ){ exp+=10; r *= 1.0e-10; } + while( r>=1.0e+19 ){ exp++; r *= 1.0e-1; } }else{ - while( r<1.0e-97L ){ exp-=100; r *= 1.0e+100L; } - while( r<1.0e+07L ){ exp-=10; r *= 1.0e+10L; } - while( r<1.0e+17L ){ exp--; r *= 1.0e+1L; } + while( r<1.0e-97 ){ exp-=100; r *= 1.0e+100; } + while( r<1.0e+07 ){ exp-=10; r *= 1.0e+10; } + while( r<1.0e+17 ){ exp--; r *= 1.0e+1; } } v = (u64)r; i = sizeof(p->z)-1;