Re: [GENERAL] numeric precision when raising one numeric to another.

2005-06-06 Thread Jan Wieck
On 5/20/2005 2:26 PM, Tom Lane wrote: numeric_power can in theory deliver an exact answer when the exponent is a positive integer. Division can deliver an exact answer in some cases too --- but the spec doesn't say it must do so when possible. So I would say that there is no spec requirement f

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-30 Thread Bruce Momjian
Alvaro Herrera wrote: > On Mon, May 30, 2005 at 11:29:48PM -0400, Bruce Momjian wrote: > > > test=> select 12345678901234567890 / 123; > > ?column? > > > > 100371373180768845 > > (1 row) > > Well, that's a bug, right? I don't think so. The fuller

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-30 Thread Alvaro Herrera
On Mon, May 30, 2005 at 11:29:48PM -0400, Bruce Momjian wrote: > test=> select 12345678901234567890 / 123; > ?column? > >100371373180768845 > (1 row) Well, that's a bug, right? -- Alvaro Herrera () "Industry suffers from the managerial

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-30 Thread Bruce Momjian
Alvaro Herrera wrote: > On Fri, May 20, 2005 at 01:03:08PM -0400, Tom Lane wrote: > > Oh, and while at it, it would be nice to solve the modulo bug that still > lurks there: > > alvherre=# select 12345678901234567890 % 123; > ?column? > -- > -45 > (1 fila) > > alvherre=# select 12

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-30 Thread Bruce Momjian
Tom Lane wrote: > Has anyone bothered to actually look into the code? > > regression=# select power(2::numeric,1000); > > power > -

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-24 Thread Alvaro Herrera
On Fri, May 20, 2005 at 01:03:08PM -0400, Tom Lane wrote: > But having said that, I don't have a problem with putting in a > pg_operator entry for numeric_power. And if someone wants to improve > the scale factor calculations therein, go for it. Oh, and while at it, it would be nice to solve the

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-21 Thread Martijn van Oosterhout
On Fri, May 20, 2005 at 12:22:33PM -0500, Jim C. Nasby wrote: > > which you could take as requiring us to provide numeric equivalents of > > every floating-point operator, but I don't find that argument very > > convincing for operations that are inherently not going to give exact > > results. The

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-20 Thread Tom Lane
Claudio Succa <[EMAIL PROTECTED]> writes: > With PostgreSQL 7.4.7 on Linux/Debian platform I had a different result so I > made the subtraction of your figure: > psql -h s1 -d rapp-test -c "select power(2::numeric,1000) - I don't know what you're getting there, but there is no power() function at

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-20 Thread Tom Lane
"Florian G. Pflug" <[EMAIL PROTECTED]> writes: > It's not only useless, it's dangerous. As fas as I know, numeric > _guarantees_ the result of a operation to be correct to the last digit. Nonsense ... see division. By your argument we should not implement numeric / numeric.

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-20 Thread Scott Marlowe
On Fri, 2005-05-20 at 12:27, Florian G. Pflug wrote: > Stephan Szabo wrote: > > On Fri, 20 May 2005, John D. Burger wrote: > > > > > >>I find all these statements about the near-uselessness of > >>NUMERIC^NUMERIC to be pretty amazing. It's fine to say, "no one seems > >>to be asking for this, so

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-20 Thread Tom Lane
Scott Marlowe <[EMAIL PROTECTED]> writes: > Are you saying that the exponent operator will return inexact results? For a fractional exponent, it generally has to, because there is no finite exact result. > If you're quoting the 92 spec, it seems to say that multiplication > precision is also imp

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-20 Thread Scott Marlowe
On Fri, 2005-05-20 at 12:03, Tom Lane wrote: > "Jim C. Nasby" <[EMAIL PROTECTED]> writes: > > Why are we allowing implicit casts from numeric to floating point? > > Because the SQL spec requires it. > > 2) If the data type of either operand of a dyadic arithmetic op- > erator

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-20 Thread Florian G. Pflug
Stephan Szabo wrote: On Fri, 20 May 2005, John D. Burger wrote: I find all these statements about the near-uselessness of NUMERIC^NUMERIC to be pretty amazing. It's fine to say, "no one seems to be asking for this, so we haven't implemented it yet", but, c'mon, folks, Postgres gets used for more

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-20 Thread Jim C. Nasby
On Fri, May 20, 2005 at 01:03:08PM -0400, Tom Lane wrote: > "Jim C. Nasby" <[EMAIL PROTECTED]> writes: > > Why are we allowing implicit casts from numeric to floating point? > > Because the SQL spec requires it. > > 2) If the data type of either operand of a dyadic arithmetic op- >

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-20 Thread Claudio Succa
17:28, venerdì 20 maggio 2005 - Tom Lane scrive: |> Has anyone bothered to actually look into the code? |> |> regression=# select power(2::numeric,1000); |> |> power |> --

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-20 Thread Florian G. Pflug
Martijn van Oosterhout wrote: On Thu, May 19, 2005 at 02:25:58PM -0700, Dann Corbit wrote: Hmmm I underestimated. pow(9.9,9.9) = Yeah, a number with x digits raised to the power with something y digits long could have a length approximating: x * (10^y) digits So two numbers bot

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-20 Thread Tom Lane
"Jim C. Nasby" <[EMAIL PROTECTED]> writes: > Why are we allowing implicit casts from numeric to floating point? Because the SQL spec requires it. 2) If the data type of either operand of a dyadic arithmetic op- erator is approximate numeric, then the data type of the re-

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-20 Thread Jim C. Nasby
Why are we allowing implicit casts from numeric to floating point? Doesn't that violate the principle of not doing any implicit casts that would potentially drop precision? It seems that about half the arguments here are related to getting unexpected or inaccurate results, presumably from the impli

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-20 Thread Tom Lane
Stephan Szabo <[EMAIL PROTECTED]> writes: > It also doesn't seem to work terribly well: It's not terribly bright about figuring out how many significant digits it should try to calculate, nor about how many it's actually got in the result. Feel free to fix that ;-) I believe the numeric exp() an

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-20 Thread Jim C. Nasby
That's because numerics default to 16 or something similar. If you want more precision just explicitly cast it: decibel=# select power(0.1::numeric(20,20),17); 0.1000 On Fri, May 20, 2005 at 09:30:16AM -0700, Stephan Szabo wrote: > > On Fri, 20 May 2005, Tom Lane wrote: > > > H

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-20 Thread Scott Marlowe
On Fri, 2005-05-20 at 11:16, Stephan Szabo wrote: > On Fri, 20 May 2005, Scott Marlowe wrote: > > > 2: How many people who DO work with large exponents and need arbitrary > > precision have looked at postgresql, typed in "select 3^100" got back > > 5.15377520732011e+47, and simply went to anothe

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-20 Thread Scott Marlowe
On Fri, 2005-05-20 at 10:37, Bruce Momjian wrote: > Scott Marlowe wrote: > > I could be wrong, and would be unoffended to be proven so, but I don't > > think I am. I think that argument is just hand waving. > > > > 2: How many people who DO work with large exponents and need arbitrary > > precis

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-20 Thread Stephan Szabo
On Fri, 20 May 2005, Tom Lane wrote: > Has anyone bothered to actually look into the code? > > regression=# select power(2::numeric,1000); > > power > ---

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-20 Thread Stephan Szabo
On Fri, 20 May 2005, Scott Marlowe wrote: > On Fri, 2005-05-20 at 09:06, Stephan Szabo wrote: > > On Fri, 20 May 2005, John D. Burger wrote: > > > > > I find all these statements about the near-uselessness of > > > NUMERIC^NUMERIC to be pretty amazing. It's fine to say, "no one seems > > > to be

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-20 Thread Bruce Momjian
Scott Marlowe wrote: > I could be wrong, and would be unoffended to be proven so, but I don't > think I am. I think that argument is just hand waving. > > 2: How many people who DO work with large exponents and need arbitrary > precision have looked at postgresql, typed in "select 3^100" got bac

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-20 Thread Tom Lane
Has anyone bothered to actually look into the code? regression=# select power(2::numeric,1000); power -

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-20 Thread Scott Marlowe
On Fri, 2005-05-20 at 09:06, Stephan Szabo wrote: > On Fri, 20 May 2005, John D. Burger wrote: > > > I find all these statements about the near-uselessness of > > NUMERIC^NUMERIC to be pretty amazing. It's fine to say, "no one seems > > to be asking for this, so we haven't implemented it yet", bu

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-20 Thread Stephan Szabo
On Fri, 20 May 2005, John D. Burger wrote: > I find all these statements about the near-uselessness of > NUMERIC^NUMERIC to be pretty amazing. It's fine to say, "no one seems > to be asking for this, so we haven't implemented it yet", but, c'mon, > folks, Postgres gets used for more than "busines

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-20 Thread Bruno Wolff III
On Fri, May 20, 2005 at 08:19:58 -0400, "John D. Burger" <[EMAIL PROTECTED]> wrote: > I find all these statements about the near-uselessness of > NUMERIC^NUMERIC to be pretty amazing. It's fine to say, "no one seems > to be asking for this, so we haven't implemented it yet", but, c'mon, > fol

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-20 Thread John D. Burger
I find all these statements about the near-uselessness of NUMERIC^NUMERIC to be pretty amazing. It's fine to say, "no one seems to be asking for this, so we haven't implemented it yet", but, c'mon, folks, Postgres gets used for more than "business cases". - John D. Burger MITRE

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-19 Thread Greg Stark
"Dann Corbit" <[EMAIL PROTECTED]> writes: > Probably, the important meaningful cases are ones that have small > exponents (HOPEFULLY less than 25) used in interest calculations. No, even in interest calculation floating point arithmetic is perfectly fine. You do your floating point arithmetic to

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-19 Thread Dann Corbit
, May 19, 2005 2:48 PM > To: Dann Corbit > Cc: Alvaro Herrera; John Burger; pgsql-general@postgresql.org > Subject: Re: [GENERAL] numeric precision when raising one numeric to > another. > > On Thu, May 19, 2005 at 02:25:58PM -0700, Dann Corbit wrote: > > Hmmm > > I

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-19 Thread Dann Corbit
ql.org > Subject: Re: [GENERAL] numeric precision when raising one numeric to > another. > > On Thu, May 19, 2005 at 02:25:58PM -0700, Dann Corbit wrote: > > Hmmm > > I underestimated. > > > > pow(9.9,9.9) = > > Yeah, a number with x d

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-19 Thread Martijn van Oosterhout
On Thu, May 19, 2005 at 02:25:58PM -0700, Dann Corbit wrote: > Hmmm > I underestimated. > > pow(9.9,9.9) = Yeah, a number with x digits raised to the power with something y digits long could have a length approximating: x * (10^y) digits So two numbers both 4 digits long can

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-19 Thread Dann Corbit
nal Message- > From: Dann Corbit > Sent: Thursday, May 19, 2005 2:20 PM > To: 'Martijn van Oosterhout' > Cc: Alvaro Herrera; John Burger; pgsql-general@postgresql.org > Subject: RE: [GENERAL] numeric precision when raising one numeric to > another. > > If you want t

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-19 Thread Dann Corbit
numeric precision when raising one numeric to > another. > > On Thu, May 19, 2005 at 10:41:51AM -0700, Dann Corbit wrote: > > We use Moshier's excellent qfloat numbers. > > http://www.moshier.net/qlib.zip > > Documentation: > > http://www.moshier.net/qlib

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-19 Thread Martijn van Oosterhout
On Thu, May 19, 2005 at 10:41:51AM -0700, Dann Corbit wrote: > We use Moshier's excellent qfloat numbers. > http://www.moshier.net/qlib.zip > Documentation: > http://www.moshier.net/qlibdoc.html > > So, if you do the following query using CONNX: > select convert(pow(9.5,5.9), varchar) > You will g

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-19 Thread Dann Corbit
ral@postgresql.org > Subject: Re: [GENERAL] numeric precision when raising one numeric to > another. > > On Wed, May 18, 2005 at 11:32:40PM -0400, Alvaro Herrera wrote: > > On Wed, May 18, 2005 at 10:46:50PM -0400, John Burger wrote: > > > For one thing. For another, I

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-19 Thread Dann Corbit
n Burger > Cc: pgsql-general@postgresql.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 > &g

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-19 Thread Martijn van Oosterhout
On Wed, May 18, 2005 at 11:32:40PM -0400, Alvaro Herrera wrote: > On Wed, May 18, 2005 at 10:46:50PM -0400, John Burger wrote: > > 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 librar

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-18 Thread Alvaro Herrera
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 ex

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-18 Thread John Burger
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 librar

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-18 Thread Tom Lane
Scott Marlowe <[EMAIL PROTECTED]> writes: > 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.

Re: [GENERAL] numeric precision when raising one numeric to

2005-05-18 Thread Scott Marlowe
On Wed, 2005-05-18 at 16:42, Tom Lane wrote: > Scott Marlowe <[EMAIL PROTECTED]> writes: > > It appears from checking the output of exponentiation of one numeric to > > another, the output is actually in floating point. Is this normal and / > > or expected? > > Yes, seeing that the only ^ operato

Re: [GENERAL] numeric precision when raising one numeric to another.

2005-05-18 Thread Tom Lane
Scott Marlowe <[EMAIL PROTECTED]> writes: > It appears from checking the output of exponentiation of one numeric to > another, the output is actually in floating point. Is this normal and / > or expected? Yes, seeing that the only ^ operator we have is float8. regression=# \do ^