pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #19811: numeric log(base, x): wrong sign of Infinity result when base < 1; base 1 accepted with x = Infinity
2+ messages / 2 participants
[nested] [flat]
* BUG #19811: numeric log(base, x): wrong sign of Infinity result when base < 1; base 1 accepted with x = Infinity
@ 2026-10-29 06:37 PG Bug reporting form <noreply@postgresql.org>
2026-10-30 21:36 ` Re: BUG #19811: numeric log(base, x): wrong sign of Infinity result when base < 1; base 1 accepted with x = Infinity Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: PG Bug reporting form @ 2026-10-29 06:37 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: 303677365@qq.com
The following bug has been logged on the website:
Bug reference: 19811
Logged by: chunling qin
Email address: 303677365@qq.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.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #19811: numeric log(base, x): wrong sign of Infinity result when base < 1; base 1 accepted with x = Infinity
2026-10-29 06:37 BUG #19811: numeric log(base, x): wrong sign of Infinity result when base < 1; base 1 accepted with x = Infinity PG Bug reporting form <noreply@postgresql.org>
@ 2026-10-30 21:36 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2026-10-30 21:36 UTC (permalink / raw)
To: 303677365@qq.com; +Cc: pgsql-bugs@lists.postgresql.org
PG Bug reporting form <noreply@postgresql.org> writes:
> 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.
Thanks for the report, but this was already reported and fixed
a couple weeks ago:
https://git.postgresql.org/gitweb/?a=commitdiff&h=94e1385ed&p=postgresql.git
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-10-30 21:36 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-29 06:37 BUG #19811: numeric log(base, x): wrong sign of Infinity result when base < 1; base 1 accepted with x = Infinity PG Bug reporting form <noreply@postgresql.org>
2026-10-30 21:36 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox