From: drh <> Date: Mon, 10 Jun 2024 18:30:44 +0000 (+0000) Subject: The aggressive rounding behavior is now only accessible using the X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Fround-up;p=thirdparty%2Fsqlite.git The aggressive rounding behavior is now only accessible using the internal sqlite3MPrintf() function. The round() SQL function uses that internal function so it can access the aggressive rounding. But ordinary extensions and the format() SQL function cannot. FossilOrigin-Name: 3dec4b35ecd68a4dace7ea17f046231e25dd79d70f4702b82461cf98fd6f850e --- diff --git a/manifest b/manifest index a1414b8c6d..8b0983fa2d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\saggressive\srounding\sbehavior\sfor\sthe\sround()\sfunction\sonly.\nFormat()\sstill\suses\sthe\sclassic\sbehavior,\sand\sthe\ssame\sbehavior\sexhibited\nby\sprintf()\sin\sglibc. -D 2024-06-10T18:10:35.427 +C The\saggressive\srounding\sbehavior\sis\snow\sonly\saccessible\susing\sthe\ninternal\ssqlite3MPrintf()\sfunction.\s\sThe\sround()\sSQL\sfunction\suses\sthat\ninternal\sfunction\sso\sit\scan\saccess\sthe\saggressive\srounding.\s\sBut\sordinary\nextensions\sand\sthe\sformat()\sSQL\sfunction\scannot. +D 2024-06-10T18:30:44.407 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -708,7 +708,7 @@ F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 F src/expr.c af9c9242be0df17280faf36c9810339de9df3d7a64ac8d33a5190a1400086ee5 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 852f93c0ef995e0c2b8983059a2b97151c194cc8259e21f5bc2b7ac508348c2a -F src/func.c 42053720bb3bf4e4e06072f22c2cde4a0477961990a31c4887f3668f8cf4543b +F src/func.c f1bceb96517bb8335c7f384ca3948b0a637f854e05f52eaeb61555b4dd956a6a F src/global.c 61a419dd9e993b9be0f91de4c4ccf322b053eb829868e089f0321dd669be3b90 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 @@ -751,7 +751,7 @@ F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 F src/pragma.c 52bfbf6dfd668b69b5eb9bd1186e3a67367c8453807150d6e75239229924f684 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c d99931f45416652895e502328ca49fe782cfc4e1ebdcda13b3736d991ebf42ce -F src/printf.c bdb1b615431486709f4a52149468b509a6f04ef5535716e3d05a12c7ddac6de0 +F src/printf.c c80f4b4b6d0f63905d4f2db47f2475b982d6e3ccfd8cbf7e9634d4b40839c1b0 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 7e8d23ce7cdbfedf351a47e759f2722e8182ca10fd7580be43f4ce1f1a228145 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 @@ -823,7 +823,7 @@ F src/trigger.c 0858f75818ed1580332db274f1032bcc5effe567cb132df5c5be8b1d800ca97f F src/update.c 732404a04d1737ef14bb6ec6b84f74edf28b3c102a92ae46b4855438a710efe7 F src/upsert.c 2e60567a0e9e8520c18671b30712a88dc73534474304af94f32bb5f3ef65ac65 F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e -F src/util.c 6bd44646223215079588dcac46206c3200d5ba29b9866fabb94dc5a98973f971 +F src/util.c f299200d350319f403ac5579f017993810949e41c709e2eb344f2cb00a07a995 F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104 F src/vdbe.c b05777c3ff2ed7b9dfc347e7cdee18e371aa6811cef1fe83454691b0dbe2cc9f F src/vdbe.h c2d78d15112c3fc5ab87f5e8e0b75d2db1c624409de2e858c3d1aafb1650bb4f @@ -2196,8 +2196,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4a790d3b28685f08bbb722057cd6a97aea08a2b2a6098562c6373fd3b5b7206c -R 73295dcd1493f41c7a4fa684616e652f +P a1b57288d7076cb9e26ac429f01e9264240d6af26243a195b2065cf667bb8bb6 +R ff68e52aa33fdcd8e876f21c1c47f49b U drh -Z 16d69236535ed95782490792d241c4e4 +Z 80a8dff00e418506573ffb4c05eb8d22 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 41e392c7aa..5e45a3f8a6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a1b57288d7076cb9e26ac429f01e9264240d6af26243a195b2065cf667bb8bb6 \ No newline at end of file +3dec4b35ecd68a4dace7ea17f046231e25dd79d70f4702b82461cf98fd6f850e \ No newline at end of file diff --git a/src/func.c b/src/func.c index ec1228bb75..d1e78ed75f 100644 --- a/src/func.c +++ b/src/func.c @@ -461,13 +461,14 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ }else if( n==0 ){ r = (double)((sqlite_int64)(r+(r<0?-0.5:+0.5))); }else{ - zBuf = sqlite3_mprintf("%#!.*f",n,r); + sqlite3 *db = sqlite3_context_db_handle(context); + zBuf = sqlite3MPrintf(db,"%!.*f",n,r); if( zBuf==0 ){ sqlite3_result_error_nomem(context); return; } sqlite3AtoF(zBuf, &r, sqlite3Strlen30(zBuf), SQLITE_UTF8); - sqlite3_free(zBuf); + sqlite3DbFreeNN(db, zBuf); } sqlite3_result_double(context, r); } diff --git a/src/printf.c b/src/printf.c index 9640b0cac8..3915fdd509 100644 --- a/src/printf.c +++ b/src/printf.c @@ -483,6 +483,7 @@ void sqlite3_str_vappendf( FpDecode s; int iRound; int j; + int mx; if( bArgList ){ realvalue = getDoubleArg(pArgList); @@ -503,11 +504,12 @@ void sqlite3_str_vappendf( }else{ iRound = precision+1; } - sqlite3FpDecode(&s, realvalue, iRound, - flag_altform2 ? 26+flag_alternateform : 16); - /* ^^^^^^^^^^^^^^^^^^^--- Undocumented behavior: - ** When both '#' and '!' flags are present, the rounding behavior - ** is changed. See "rule 3" in the sqlite3FpDecode docs. */ + if( flag_altform2 ){ + mx = 26 + ((pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)!=0); + }else{ + mx = 16; + } + sqlite3FpDecode(&s, realvalue, iRound, mx); if( s.isSpecial ){ if( s.isSpecial==2 ){ bufpt = flag_zeropad ? "null" : "NaN"; diff --git a/src/util.c b/src/util.c index e4c8159a3f..e36e78e2f4 100644 --- a/src/util.c +++ b/src/util.c @@ -1052,19 +1052,16 @@ static SQLITE_NOINLINE int shouldRoundUp(const char *z, int n, int iRound){ ** (2) If the next digit is 5 or more, then round up. ** ** (3) Round up if the next digit is a 4 followed by three or -** more 9 digits and all digits after the 4 up to the -** antipenultimate digit are 9. Otherwise truncate. +** more 9 digits and all significant digits after the 4 are +** 9 and mxRound is 27. Otherwise truncate. ** -** Rule (3) is so that things like round(0.15,1) will come out as 0.2 +** Rule (3) is used by the built-in round() function to do more aggressive +** rounding so that things like round(0.15,1) will come out as 0.2 ** even though the stored value for 0.15 is really ** 0.1499999999999999944488848768742172978818416595458984375 and ought ** to round down to 0.1. Rule (3) is only applied if mxRound==27. -** -** This routine is normally only called from printf()/format(). In that -** case, mxRound is usually 16 but is increased to 26 with the "!" flag. -** Undocumented behavior: mxRound is 27 with the "#" and "!" flags. The -** round() function uses this undocumented flag combination to activate -** rounding rule (3). +** And mxRound is only 27 if the internal sqlite3MPrintf() formatter is +** used and the "!" flag is included. */ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){ int i;