Hi,

The SQL function log() returns incorrect results in these cases:
```
evantest=# SELECT log(0.5::numeric, 'Infinity'::numeric);
  log
----------
Infinity
(1 row)

evantest=# SELECT log(1::numeric, 'Infinity'::numeric);
  log
----------
Infinity
(1 row)
```

log(base, value) = ln(value) / ln(base)

ln(0.5) is negative, so the first should return negative infinity; ln(1) is 
zero, so the second should fail with division by zero.

Verifying in Python:
```
>>> print(math.log(math.inf, 0.5))
-inf

>>> print(math.log(math.inf, 1));
Traceback (most recent call last):
 File "<python-input-3>", line 1, in <module>
   print(math.log(math.inf, 1));
         ~~~~~~~~^^^^^^^^^^^^^
ZeroDivisionError: division by zero
```

Also, verifying with PG itself using division:
```
evantest=# select ln('Infinity'::numeric)/ln(0.5::numeric);
?column?
-----------
-Infinity
(1 row)

evantest=# select ln('Infinity'::numeric)/ln(1::numeric);
ERROR:  division by zero
```

This issue was introduced in v14.

Please see the attached patch for the fix.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/




Attachment: v1-0001-Fix-numeric-log-with-an-infinite-argument-and-a-b.patch
Description: Binary data

Reply via email to