int4, int8, real ....division... - Mailing list pgsql-bugs

From Gyenese Pál Attila
Subject int4, int8, real ....division...
Date
Msg-id 51404.195.70.45.71.1084985674.squirrel@mediagnost.hu
Whole thread Raw
Responses Re: int4, int8, real ....division...  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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





pgsql-bugs by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: BUG #1144: comments don't get propagated
Next
From: Tom Lane
Date:
Subject: Re: int4, int8, real ....division...