Skip site navigation (1) Skip section navigation (2)

postgres arithmetic: raising to nth power

From: Ennio-Sr <nasr(dot)laili(at)tin(dot)it>
To: pgsql-novice(at)postgresql(dot)org
Subject: postgres arithmetic: raising to nth power
Date: 2005-09-29 19:36:57
Message-ID: 20050929193657.GA5327@deby.ei.hnet (view raw or flat)
Lists: 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

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

# Let's see if my guess is correct:

 select 100*(1.10)^1277    
(1 row)

 select 7.21869922862002/365 
(1 row)

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

 select 7.21869922862002/365::float 
(1 row)

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

 select 100*(1.10)^1277::float 
(1 row)

# However, using more reasonable numbers:

 select (1.10)^12 
(1 row)

 select 100*(1.10)^12 
(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?

Thanks for your attention.

[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 LaneDate: 2005-09-29 22:27:24
Subject: Re: postgres arithmetic: raising to nth power
Previous:From: Obe, Regina DND\MISDate: 2005-09-29 13:30:17
Subject: Re: Query in SQL statement

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group