Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather than an error, and have 0 ^

From: Simon Riggs <simon(at)2ndquadrant(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Have numeric 0 ^ 4.3 return 1, rather than an error, and have 0 ^
Date: 2008-05-09 08:00:36
Message-ID: 1210320036.4268.544.camel@ebony.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

On Thu, 2008-05-08 at 18:34 -0400, Bruce Momjian wrote:
> Tom Lane wrote:
> > momjian(at)postgresql(dot)org (Bruce Momjian) writes:
> > > Have numeric 0 ^ 4.3 return 1, rather than an error, and have 0 ^ 0.0
> > > return 1, rather than error.
> >
> > This is wrongly described, and the implementation is still not correct
> > either, because it should throw an error for negative exponents.
> > Would you please *read* that wikipedia page you keep citing?
> > http://en.wikipedia.org/wiki/Exponentiation#Powers_of_zero
>
> I think this is fixed in the version I just committed:
>
> test=> select 0 ^ (-1);
> ERROR: invalid argument for power function
> test=> select 0 ^ (-1.0);
> ERROR: invalid argument for power function

Hopefully this only occurs for 0 ^ (n)? A negative exponent isn't a
problem for y ^ x when y <> 0 and x < 0. Just checking you don't just
throw out an error for any negative exponent, which is what "invalid
argument" sounds like, to me.

Wikipedia says that exponentiation of zero to a negative power implies
division by zero, so shouldn't we throw a "division by zero" error?

--
Simon Riggs
2ndQuadrant http://www.2ndQuadrant.com

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message User Achernow 2008-05-09 12:08:12 libpqtypes - libpqtypes: added source file name and small description at
Previous Message Tom Lane 2008-05-09 05:25:54 pgsql: Fix bogus expected output that should have made it quite clear