Обсуждение: bug in numeric_power() function

Поиск
Список
Период
Сортировка

bug in numeric_power() function

От
"Richard Wang"
Дата:
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 




Re: bug in numeric_power() function

От
"Dann Corbit"
Дата:
> -----Original Message-----
> From: pgsql-hackers-owner@postgresql.org [mailto:pgsql-hackers-
> owner@postgresql.org] On Behalf Of Richard Wang
> Sent: Tuesday, March 11, 2008 7:38 PM
> To: pgsql-hackers@postgresql.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).



Re: bug in numeric_power() function

От
Tom Lane
Дата:
"Richard Wang" <ruc_wang@hotmail.com> writes:
> 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

Hmm, seems like the numeric and float8 power operators don't agree
about 0^0 either...
        regards, tom lane


Re: bug in numeric_power() function

От
"Richard Wang"
Дата:
I also have a question here:
isn't dpow enough for calculation?
Why added numeric_power?
"Tom Lane" <tgl@sss.pgh.pa.us> д����Ϣ����:12538.1205298992@sss.pgh.pa.us...
> "Richard Wang" <ruc_wang@hotmail.com> writes:
>> 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
>
> Hmm, seems like the numeric and float8 power operators don't agree
> about 0^0 either...
>
> regards, tom lane
>
> -- 
> Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>