]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Improve overflow/underflow handling in regr_r2().
authorDean Rasheed <dean.a.rasheed@gmail.com>
Wed, 3 Jun 2026 08:01:13 +0000 (09:01 +0100)
committerDean Rasheed <dean.a.rasheed@gmail.com>
Wed, 3 Jun 2026 08:01:13 +0000 (09:01 +0100)
commitd58ec50e0faae364fa59cdb88eba7e23b55ab583
tree86eae85f3938da1a5c0fcfdb010116e52994572d
parent95b6ec52e684e5de743e5bf4a2303f6cac466682
Improve overflow/underflow handling in regr_r2().

Commit 6498287696d improved corr()'s final function to cope with
overflow/underflow in the final calculation, and clamped its result to
[-1, 1] in case of roundoff error. Improve regr_r2() in a similar way,
clamping its result to [0, 1].

Arguably this is a bug fix, but given the lack of prior complaints,
refrain from back-patching, as we did with 6498287696d.

Reported-by: Chengpeng Yan <chengpeng_yan@outlook.com>
Author: Chengpeng Yan <chengpeng_yan@outlook.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/33E01656-BB3B-46E9-A41F-24A01A7C35F4@outlook.com
src/backend/utils/adt/float.c
src/test/regress/expected/aggregates.out
src/test/regress/sql/aggregates.sql