Re: ERROR: value out of range: underflow in numeric log calculation

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gallacher Neil <Neil(dot)Gallacher(at)gstt(dot)nhs(dot)uk>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: ERROR: value out of range: underflow in numeric log calculation
Date: 2023-11-21 18:34:10
Message-ID: 1526793.1700591650@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Gallacher Neil <Neil(dot)Gallacher(at)gstt(dot)nhs(dot)uk> writes:
> When executing log calculations (example below):
> SELECT 1.0 * exp(-1.0 *(ln(2) * (1695993520/86400.0)) / 0.04) AS result_test;
> The following error occurs.
> ERROR: value out of range: underflow

Yup.

> I can however understand that an individual might wish to know that the result of a calculation cannot be represented by the system due to its small value however I don't believe it should be the default behaviour.

You'd be in a minority on that opinion. In this case you could work
around it by asking for the calculation to be done in numeric rather
than float8:

regression=# SELECT 1.0 * exp(-1.0 *(ln(2::numeric) * (1695993520/86400.0)) / 0.04) AS result_test;
result_test
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
(1 row)

but I'm not sure how far that covers your real use-case.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Ivan Trofimov 2023-11-22 00:13:46 libpq: pipeline mode might desynchronize client and server
Previous Message vignesh C 2023-11-21 18:02:09 Re: BUG #18203: Logical Replication initial sync failure