pgsql: Fix two edge cases in numeric log(base, val).

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix two edge cases in numeric log(base, val).
Date: 2026-10-15 15:25:29
Message-ID: E1xHNKj-00000001kYj-46EO@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix two edge cases in numeric log(base, val).

For log(base, +Infinity) where 0 < base < 1, the correct output
is -Infinity, not +Infinity as we had been giving.

log(1, x) is erroneous regardless of x. Formerly we returned
+Infinity when x is +Infinity, and threw a rather confusing
"division by zero" error for finite-positive x. Change both
cases to report "cannot take logarithm using base one".

While the cases with infinite inputs are clearly wrong, it's
not clear that people would appreciate such a behavior change
in stable branches, so fix master only.

Author: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Reviewed-by: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/08270B8B-634F-4381-9D6F-9BDB18DA82A0@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/94e1385ed28509bee486aa0be40dea78b9e083c3

Modified Files
--------------
src/backend/utils/adt/numeric.c | 24 ++++++++++++++++++++++--
src/test/regress/expected/numeric.out | 10 +++++++++-
src/test/regress/sql/numeric.sql | 2 ++
3 files changed, 33 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2026-10-15 15:39:42 pgsql: Update v18 .abi-compliance-history for changes in reorderbuffer.
Previous Message Álvaro Herrera 2026-10-15 14:40:01 pgsql: Update .abi-compliance-history for changes in reorderbuffer.h