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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-bugs by date

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