aboutsummaryrefslogtreecommitdiff
path: root/src/func.c
diff options
context:
space:
mode:
authordrh <>2023-08-30 16:03:27 +0000
committerdrh <>2023-08-30 16:03:27 +0000
commit7bb5a6db4036e3956aadb71be0c390d3a4c32243 (patch)
tree06d647b3f04b261f7d388e256efb71b018e06e24 /src/func.c
parent85a05d895aa839b148686bdca0ed0486042e98cb (diff)
downloadsqlite-7bb5a6db4036e3956aadb71be0c390d3a4c32243.tar.gz
sqlite-7bb5a6db4036e3956aadb71be0c390d3a4c32243.zip
Fix the AVG() and TOTAL() functions (after the SUM() fix of [77d3dcd283595c52])
so that they work with infinitites. Fixes a bug introduced by check-in. [c63e26e705f5e967]. Bug reported by [forum:/forumpost/8960fb40cc|forum post 8960fb40cc]. FossilOrigin-Name: 6df6f17ccb404c648076ccff4200d0eb5437f0e3e82424bf3da5ea682b107bb4
Diffstat (limited to 'src/func.c')
-rw-r--r--src/func.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/func.c b/src/func.c
index 333252348..8739035b5 100644
--- a/src/func.c
+++ b/src/func.c
@@ -1907,7 +1907,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);
}
@@ -1920,7 +1921,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);
}