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

Started by Tom Laneabout 1 month ago1 messagescommitters
Jump to latest
#1Tom Lane
tgl@sss.pgh.pa.us

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.evan.chao@gmail.com>
Reviewed-by: Matthias van de Meent <boekewurm+postgres@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: /messages/by-id/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(-)