| From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | 303677365(at)qq(dot)com |
| Subject: | BUG #19811: numeric log(base, x): wrong sign of Infinity result when base < 1; base 1 accepted with x = Infinity |
| Date: | 2026-10-29 06:37:56 |
| Message-ID: | 19811-3e5c60ea0ef2a9b7@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 19811
Logged by: chunling qin
Email address: 303677365(at)qq(dot)com
PostgreSQL version: 18.6
Operating system: Linux x86_64
Description:
The two-argument numeric logarithm returns +Infinity for x = Infinity
regardless of the base. For bases between 0 and 1 the correct result is
-Infinity, and for base 1 the call should be rejected.
Self-contained test (official postgres:latest docker image, 18.6):
SELECT log('0.5'::numeric, '1e308'::numeric); --
-1023.15385322530760 (correct sign)
SELECT log('0.5'::numeric, 'Infinity'::numeric); -- Infinity (wrong:
should be -Infinity)
SELECT log('0.1'::numeric, 'Infinity'::numeric); -- Infinity (wrong)
SELECT log('0.25'::numeric, 'Infinity'::numeric); -- Infinity (wrong)
Controls:
SELECT log('2'::numeric, 'Infinity'::numeric); -- Infinity
(correct, base > 1)
SELECT ln('Infinity'::numeric); -- Infinity
(correct)
SELECT log('0.5'::numeric, '-Infinity'::numeric); -- ERROR: cannot take
logarithm of a negative number
The function is internally inconsistent: with a large finite argument the
sign is correct (-1023 for 1e308, since ln(x)/ln(0.5) is negative), but at
exactly Infinity the sign flips to positive. Mathematically log_b(Infinity)
= ln(Infinity)/ln(b) = Infinity/ln(b), which is -Infinity for 0 < b < 1 and
+Infinity for b > 1.
Base 1 is also not rejected when x = Infinity:
SELECT log('1'::numeric, '12.34'::numeric); -- ERROR: division by
zero (correct rejection)
SELECT log('1'::numeric, 'Infinity'::numeric); -- Infinity
(wrong: the same call with a finite x is rejected)
The Infinity special case in the numeric log implementation appears to
shortcut the ln(x)/ln(b) computation without considering the sign of ln(b),
or the ln(b) = 0 case.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Narayanan Venkateswaran | 2026-10-29 06:41:05 | Re: BUG #19800: Wrong results: self-join elimination drops an ORDER BY sort key with GROUPING SETS / CUBE / ROLLUP |
| Previous Message | PG Bug reporting form | 2026-10-29 06:32:46 | BUG #19810: to_char(): float V-format overflow yields 'Infinity' or NaN; format after decimal point dropped |