Re: Arbitrary precision arithmatic with pgsql

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>
Cc: Rajesh Kumar Mallah <mallah(at)trade-india(dot)com>, Michael Glaesemann <grzm(at)myrealbox(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Arbitrary precision arithmatic with pgsql
Date: 2004-08-31 15:04:52
Message-ID: 29456.1093964692@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Jan Wieck <JanWieck(at)Yahoo(dot)com> writes:
> I agree that doing
> select 2::numeric ^ 100;
> should emit some sort of a warning.

I do not. The conversion of 2::numeric to float is exact, so AFAICS
the only way to do that would be to make *every* coercion of numeric to
float emit a warning. This is not a reasonable response to the fact
that Rajesh is unaware of the set of available operators. Moreover
it would essentially break float constants (since "2.0" starts life
as numeric and is only cast to float when the context demands).

I'd be in favor of adding a numeric^numeric operator to ease access to
the existing pow() code, but I'm not sure this makes the issue go away
entirely. It looks like "select 2 ^ 100" would still default to being
a float operation.

regression=# create operator ^ (procedure=pow, leftarg=numeric, rightarg=numeric);
CREATE OPERATOR
regression=# select 2::numeric ^ 100;
?column?
--------------------------------------------------
1267650600228229401496703205376.0000000000000000
(1 row)

regression=# select 2 ^ 100;
?column?
----------------------
1.26765060022823e+30
(1 row)

regression=# select 2.0 ^ 100;
?column?
--------------------------------------------------
1267650600228229401496703205376.0000000000000000
(1 row)

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jan Wieck 2004-08-31 15:12:40 Re: Arbitrary precision arithmatic with pgsql
Previous Message Michael Glaesemann 2004-08-31 14:27:11 Re: Arbitrary precision arithmatic with pgsql