## postgres arithmetic: raising to nth power

From: Ennio-Sr pgsql-novice(at)postgresql(dot)org postgres arithmetic: raising to nth power 2005-09-29 19:36:57 20050929193657.GA5327@deby.ei.hnet (view raw or flat) 2005-09-29 19:36:57 from Ennio-Sr  2005-09-29 22:27:24 from Tom Lane   2005-09-30 00:05:59 from Ennio-Sr  2005-09-29 22:34:45 from Andrej Ricnik-Bay   2005-09-29 23:26:27 from Ennio-Sr pgsql-novice
```[Using postgres (PostgreSQL) 7.4.7 on
GNU/Linux  2.4.27-1-386 - Debian/Sarge]
----------------------------------------

Hi all,
testing a few arithmetic calculations to make sure I understood how
they worked before including them in a a query I met with the following
results:

select 100*1.10^1277/365::float: 	# supposedly: first calculates 1.10^1277
----------------------------------	# then multiplies by 100 and divide by 365
1.97772581606028e+52
(1 row)

# Let's see if my guess is correct:

select 100*(1.10)^1277
----------------------
7.21869922862002e+54
(1 row)

select 7.21869922862002/365
-----------------------------
0.01977725816060279452
(1 row)

# Hmmm: same result, except there is no multiplication by 100!

select 7.21869922862002/365::float
------------------------------------
0.0197772581606028
(1 row)

# the presence of either float or numeric dowsn't alter the result.

select 100*(1.10)^1277::float
-------------------------------
7.21869922862002e+54
(1 row)

# However, using more reasonable numbers:

select (1.10)^12
------------------
3.138428376721
(1 row)

select 100*(1.10)^12
----------------------
313.8428376721
(1 row)

the result is correct.
-------------------------------------

So, the problem is: how can I get to know which results are correct and
which aren't?  May be the presence on the trailing 'e+..' is signalling
there is an error?
Could somebody give me a short explanation or suggest further readings?

Regards,
Ennio.

--
[Perche' usare Win\$ozz (dico io) se ..."anche uno sciocco sa farlo.   \\?//
Fa' qualche cosa di cui non sei capace!"  (diceva Henry Miller) ]    (°|°)
[Why use Win\$ozz (I say) if ... "even a fool can do that.              )=(
Do something you aren't good at!" (as Henry Miller used to say) ]

```

### pgsql-novice by date

 Next: From: Tom Lane Date: 2005-09-29 22:27:24 Subject: Re: postgres arithmetic: raising to nth power Previous: From: Obe, Regina DND\MIS Date: 2005-09-29 13:30:17 Subject: Re: Query in SQL statement