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-16T21:18:43Z
Lists: pgsql-hackers
Dean Rasheed <dean.a.rasheed@gmail.com> writes:
> I just had a thought: a simpler (and probably faster and more
> accurate) solution would be to use frexp() and ldexp(), which are both
> part of C99, so ought to be OK.

Seems like a plan.  We're already relying on ldexp() in pg_prng.c,
so I doubt there's a portability issue.  Reading the man page for
frexp(), we might want to special-case Inf and NaN inputs to avoid
assuming what it will do with those.  But that would only be needed
in the slow path where we're recovering from overflow/underflow.

			regards, tom lane