Re: [HACKERS] bug in numeric_power() function

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Richard Wang <ruc_wang(at)hotmail(dot)com>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] bug in numeric_power() function
Date: 2008-05-07 20:12:24
Message-ID: 200805072012.m47KCOZ04930@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Richard Wang wrote:
> 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

I have developed the attached patch which fixes 0 ^ 123.3. It also
fixes the case for 0 ^ 0.0 so it returns 1 instead of an error --- see
the C comment for why one is the proper return value. float pow()
already returned one in this case:

test=> select 0 ^ 0;
?column?
----------
1
(1 row)

test=> select 0 ^ 0.0;
?column?
----------
1
(1 row)

test=> select 0 ^ 3.4;
?column?
----------
1
(1 row)

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
/pgpatches/power text/x-diff 1.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2008-05-07 20:13:45 Re: Posting to hackers and patches lists
Previous Message Gregory Stark 2008-05-07 20:08:42 Re: Posting to hackers and patches lists

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2008-05-07 20:13:45 Re: Posting to hackers and patches lists
Previous Message Gregory Stark 2008-05-07 20:08:42 Re: Posting to hackers and patches lists