pgsql: Improve overflow/underflow handling in regr_intercept().

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Improve overflow/underflow handling in regr_intercept().
Date: 2026-06-03 08:22:50
Message-ID: E1wUgsE-000sCG-2A@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Improve overflow/underflow handling in regr_intercept().

As with corr() and regr_r2(), improve regr_intercept()'s final
function to cope with overflow/underflow in the final calculation.
Here, instead of using sqrt(), we use frexp() and ldexp() to recover,
if an overflow or underflow is detected, so that the multiplication
and division steps operate on normalised mantissas, and cannot
overflow or underflow.

As with 6498287696d, and the previous commit improving regr_r2(), this
is arguably a bug fix, but given the lack of prior complaints, refrain
from back-patching.

Reported-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Author: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Reviewed-by: Chengpeng Yan <chengpeng_yan(at)outlook(dot)com>
Discussion: https://postgr.es/m/33E01656-BB3B-46E9-A41F-24A01A7C35F4@outlook.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/eb8e76e130fd8bd42982d597f5a66f08b13380c0

Modified Files
--------------
src/backend/utils/adt/float.c | 39 ++++++++++++++++++++++++++++++--
src/test/regress/expected/aggregates.out | 12 ++++++++++
src/test/regress/sql/aggregates.sql | 2 ++
3 files changed, 51 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-06-03 09:48:25 pgsql: Fix race in ReplicationSlotRelease() for ephemeral slots
Previous Message Dean Rasheed 2026-06-03 08:03:37 pgsql: Improve overflow/underflow handling in regr_r2().