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

int4, int8, real ....division...

From: Gyenese Pál Attila <gyenese(at)mediagnost(dot)hu>
To: <pgsql-bugs(at)postgresql(dot)org>
Subject: int4, int8, real ....division...
Date: 2004-05-19 16:54:34
Message-ID: 51404.195.70.45.71.1084985674.squirrel@mediagnost.hu (view raw or flat)
Thread:
Lists: pgsql-bugs
pgsql-7.4.2

I think it's not a bug, just interesting results:

SELECT   9223372036854775807/(365*10000000)  ;
result: -14300526699
wrong

SELECT   ( 9223372036854775807/365 )/10000000  ;
result: 2526951242
good

SELECT   ( 9223372036854775807::real /(365*10000000) )  ;
result: -14300526699,6589
wrong

SELECT   ( 9223372036854775807 /(365*10000000)::real )  ;
result: -14300526699,6589
wrong

SELECT   ( 9223372036854775807 /(365*10000000)::real )  ;
result: -14300526699,6589
wrong

SELECT   ( 9223372036854775807/(365*10000000::real) )  ;
result:  2526951242,97391
good

SELECT   ( 9223372036854775807/(365::real*10000000) )  ;
result:  2526951242,97391
good



REASON IS:

SELECT 365*10000000 ;
result: -644967296
wrong

but

SELECT 365*10000000::int8 ;
result: 3650000000
good



If this operation embended in complex expression,
then very difficult to find the reason of computation error.
This misstake comes only after the border of int4 and int8.


-------------------------------------------------
Gyenese Pál Attila
számítástechnikai vezető
MEDIAGNOST KFT.
1106 Fehér út 10
Tel.: 431.87.74
Fax.: 265.20.73




Responses

pgsql-bugs by date

Next:From: Bruce MomjianDate: 2004-05-20 00:16:44
Subject: Re: Renaming a table leaves orphaned implicit sequences which
Previous:From: D'Arcy J.M. CainDate: 2004-05-19 10:35:49
Subject: Re: BUG #1154: no python interface anymore

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