From: drh <> Date: Wed, 30 Aug 2023 16:08:30 +0000 (+0000) Subject: Fix the AVG() and TOTAL() functions so that they work with infinitites. X-Git-Tag: version-3.43.1~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6541f0180565b1e281ccae2f7eb4771aefd327f0;p=thirdparty%2Fsqlite.git Fix the AVG() and TOTAL() functions so that they work with infinitites. FossilOrigin-Name: 97e20716c7c5c9c96a693835f99692d4cea088edebb9e422057bcb59829b798f --- diff --git a/manifest b/manifest index 6310916cfe..8841ba64b7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sissue\swith\sinfinity\shandling\sby\sthe\sSUM()\sfunction\sthat\sgoes\sback\nto\sthe\sextended-precision\sSUM()\senhancement\sof\ncheck-in\sc63e26e705f5e967.\s\sProblem\sreported\sby\nforum\spost\s1c06ddcacc86032a. -D 2023-08-28T12:57:30.011 +C Fix\sthe\sAVG()\sand\sTOTAL()\sfunctions\sso\sthat\sthey\swork\swith\sinfinitites. +D 2023-08-30T16:08:30.623 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -637,7 +637,7 @@ F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 F src/expr.c 1affe0cc049683ef0ef3545d9b6901508556b0ef7e2892a344c3df6d7288d79d F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a7fcbf7e66d14dbb73cf49f31489ebf66d0e6006c62b95246924a3bae9f37b36 -F src/func.c f480d46974ecc84fefdd429377158981b974e0e33d656f1b0e919ba7c4bdd390 +F src/func.c 3c8e02958a3d4272659fcb234133b7572794ece60571779e88dd96ec16bae0d6 F src/global.c 29f56a330ed9d1b5cd9b79ac0ca36f97ac3afc730ff8bfa987b0db9e559d684d F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 @@ -1156,7 +1156,7 @@ F test/fts4umlaut.test fcaca4471de7e78c9d1f7e8976e3e8704d7d8ad979d57a739d00f3f75 F test/fts4unicode.test 82a9c16b68ba2f358a856226bb2ee02f81583797bc4744061c54401bf1a0f4c9 F test/fts4upfrom.test f25835162c989dffd5e2ef91ec24c4848cc9973093e2d492d1c7b32afac1b49d F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d -F test/func.test 719076723b13a6bfcff7b00b7987b1d7b06876ceb71e868b3d13d571d9b42cae +F test/func.test cbcf086273529d4a99b7199086da637a99039d2cad81dd7d7c4c9e25258ae164 F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f F test/func3.test 600a632c305a88f3946d38f9a51efe145c989b2e13bd2b2a488db47fe76bab6a F test/func4.test 2285fb5792d593fef442358763f0fd9de806eda47dbc7a5934df57ffdc484c31 @@ -2092,9 +2092,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 289d2a0e64d760aded18cd457fe06a55f3fa0bfd56914e7b41297e437861b4d9 -Q +77d3dcd283595c52f24c07fc59ba60c9133b71c440cf3f799cf48c907c6fae3e -R 251f1dbffa3c027b9a3e01ebf2e3f4a3 +P 692266abd107920ef8bec16c5e2c6226746948140dd8da17cdf2132fee4338f6 +Q +6df6f17ccb404c648076ccff4200d0eb5437f0e3e82424bf3da5ea682b107bb4 +R 91c512eb5ecf2b495e648d6381e248bf U drh -Z 24a16c64465617b106b86b6313970d44 +Z c3c82b30f339c4d0d44d7d774602974f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9c8477f216..ebf372b137 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -692266abd107920ef8bec16c5e2c6226746948140dd8da17cdf2132fee4338f6 \ No newline at end of file +97e20716c7c5c9c96a693835f99692d4cea088edebb9e422057bcb59829b798f \ No newline at end of file diff --git a/src/func.c b/src/func.c index 70fda85927..e551bba818 100644 --- a/src/func.c +++ b/src/func.c @@ -1832,7 +1832,8 @@ static void avgFinalize(sqlite3_context *context){ if( p && p->cnt>0 ){ double r; if( p->approx ){ - r = p->rSum+p->rErr; + r = p->rSum; + if( !sqlite3IsNaN(p->rErr) ) r += p->rErr; }else{ r = (double)(p->iSum); } @@ -1845,7 +1846,8 @@ static void totalFinalize(sqlite3_context *context){ p = sqlite3_aggregate_context(context, 0); if( p ){ if( p->approx ){ - r = p->rSum+p->rErr; + r = p->rSum; + if( !sqlite3IsNaN(p->rErr) ) r += p->rErr; }else{ r = (double)(p->iSum); } diff --git a/test/func.test b/test/func.test index 4743e109bd..aea372e08e 100644 --- a/test/func.test +++ b/test/func.test @@ -1549,8 +1549,8 @@ do_catchsql_test func-37.120 { # Incorrect handling of infinity by SUM(). # do_execsql_test func-38.100 { - WITH t1(x) AS (VALUES(9e+999)) SELECT sum(x) FROM t1; - WITH t1(x) AS (VALUES(-9e+999)) SELECT sum(x) FROM t1; -} {Inf -Inf} + WITH t1(x) AS (VALUES(9e+999)) SELECT sum(x), avg(x), total(x) FROM t1; + WITH t1(x) AS (VALUES(-9e+999)) SELECT sum(x), avg(x), total(x) FROM t1; +} {Inf Inf Inf -Inf -Inf -Inf} finish_test