Re: numeric precision when raising one numeric to another.

From: "Dann Corbit" <DCorbit(at)connx(dot)com>
To: "Alvaro Herrera" <alvherre(at)surnet(dot)cl>, "John Burger" <john(at)mitre(dot)org>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: numeric precision when raising one numeric to another.
Date: 2005-05-19 17:26:25
Message-ID: D425483C2C5C9F49B5B7A41F89441547055BC1@postal.corporate.connx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

PostgreSQL has a numeric exp() function and a numeric ln() function, so
a numeric pow() function is trivial.

pow(A,z) = exp(z*ln(A))

Probably, it could be made a bit more efficient if specially tuned so as
to not require these functions.

Newton's method (or something of that nature) could obviously be used to
write a more generic version. The double C function can provide the
starting estimate.

> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-
> owner(at)postgresql(dot)org] On Behalf Of Alvaro Herrera
> Sent: Wednesday, May 18, 2005 8:33 PM
> To: John Burger
> Cc: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] numeric precision when raising one numeric to
> another.
>
> On Wed, May 18, 2005 at 10:46:50PM -0400, John Burger wrote:
> > >>Considering that the SQL spec says the result of multiplication of
> > >>exact
> > >>numeric types is exact numeric types of precision S1+S2, and
> > >>exponentiation is nothing more than repeated multiplication,
> > >
> > >... not when the exponent is non-integral.
> >
> > For one thing. For another, I believe the standard C library only
has
> > floating point exponentiation functions, not that there aren't
plenty
> > of numeric libraries with integral ones. Finally, exponentiated
> > numbers get real big, real fast, and the floating point types can
hold
> > much larger magnitudes than the integer types, albeit inexactly.
For
> > example, on the Mac I'm using now, long long ints max out at about
> > 10^19, while long doubles can represent 10^308.
>
> Well, we already have an interesting library of mathematical functions
> for NUMERIC (which is an arbitrary precision type, so it wouldn't
matter
> how big the result would get). I think the only reason we don't have
a
> NUMERIC exponentiation function is that nobody has implemented it.
>
> --
> Alvaro Herrera (<alvherre[a]surnet.cl>)
> "People get annoyed when you try to debug them." (Larry Wall)
>
> ---------------------------(end of
broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to
majordomo(at)postgresql(dot)org

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2005-05-19 17:30:41 Re: Postgres in government
Previous Message Robert Treat 2005-05-19 17:25:19 Re: Postgres in government