Numeric x^y for negative x

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Numeric x^y for negative x
Date: 2021-06-29 11:08:01
Message-ID: CAEZATCW6Dvq7+3wN3tt5jLj-FyOcUgT5xNoOqce5=6Su0bCR0w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Numeric x^y is supported for x < 0 if y is an integer, but this
currently fails if y is outside the range of an int32:

SELECT (-1.0) ^ 2147483647;
?column?
---------------------
-1.0000000000000000
(1 row)

SELECT (-1.0) ^ 2147483648;
ERROR: cannot take logarithm of a negative number

because only the power_var_int() code path in power_var() handles
negative bases correctly. Attached is a patch to fix that.

Regards,
Dean

Attachment Content-Type Size
numeric-pow-negative-base.patch text/x-patch 3.7 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message John Naylor 2021-06-29 11:20:38 Re: speed up verifying UTF-8
Previous Message Amit Kapila 2021-06-29 11:07:27 Re: Refactor "mutually exclusive options" error reporting code in parse_subscription_options