Re: bug in numeric_power() function

From: "Dann Corbit" <DCorbit(at)connx(dot)com>
To: "Richard Wang" <ruc_wang(at)hotmail(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bug in numeric_power() function
Date: 2008-03-12 05:05:07
Message-ID: D425483C2C5C9F49B5B7A41F8944154701000CF1@postal.corporate.connx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

> -----Original Message-----
> From: pgsql-hackers-owner(at)postgresql(dot)org [mailto:pgsql-hackers-
> owner(at)postgresql(dot)org] On Behalf Of Richard Wang
> Sent: Tuesday, March 11, 2008 7:38 PM
> To: pgsql-hackers(at)postgresql(dot)org
> Subject: [HACKERS] bug in numeric_power() function
>
> I expected 0 ^ 123.3 to be 0, but it reported error as follows
>
> postgres=# select 0 ^ 123.3;
> ERROR: cannot take logarithm of zero
>
> I find that there is a bug in numeric_power() function
> the function caculates a ^ b based on the algorithm e ^ (lna * b)
> as you see, ln0 is not valid

It seems an obvious work-around that:
if (b == 0) return 1;
if (a == 0) return 0;
could be inserted at the top.

Aside:
Having the ^ operator overloaded for exponentiation surprises me.

Does it really have the right precedence for performing exponentiation?
(E.g. you cannot do this in C++ because ^ will have the precedence of
xor, which is wrong).

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-03-12 05:16:32 Re: bug in numeric_power() function
Previous Message Richard Wang 2008-03-12 02:37:34 bug in numeric_power() function

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2008-03-12 05:16:32 Re: bug in numeric_power() function
Previous Message Richard Wang 2008-03-12 02:37:34 bug in numeric_power() function