From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: 303677365@qq.com
Subject: BUG #19811: numeric log(base, x): wrong sign of Infinity result when base < 1; base 1 accepted with x = Infinity
Date: Thu, 29 Oct 2026 06:37:56 +0000
Message-ID: <19811-3e5c60ea0ef2a9b7@postgresql.org> (raw)
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, 303677365@qq.com
Subject: Re: BUG #19811: numeric log(base, x): wrong sign of Infinity result when base < 1; base 1 accepted with x = Infinity
In-Reply-To: <19811-3e5c60ea0ef2a9b7@postgresql.org>
References: <19811-3e5c60ea0ef2a9b7@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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