Re: [PATCH] Fix overflow and underflow in regr_r2()

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Chengpeng Yan <chengpeng_yan@outlook.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2026-05-16T18:42:59Z
Lists: pgsql-hackers
Dean Rasheed <dean.a.rasheed@gmail.com> writes:
> On Sat, 16 May 2026 at 17:45, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> One simple change that might make things better is to compute
>> 	PG_RETURN_FLOAT8((Sy - Sx * (Sxy / Sxx)) / N);
>> on the theory that the sums of products are likely to both be large.

> Hmm, that isn't necessarily better.

True.  We could do something like

	(Sy - exp(log(Sx) + log(Sxy) - log(Sxx))) / N

but this'd require additional special-case code to deal with zero
or negative Sx and Sxy, so it's feeling rather tedious.

			regards, tom lane