dbTalk Databases Forums  

Re: [BUGS] int4, int8, real ....division...

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss Re: [BUGS] int4, int8, real ....division... in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] int4, int8, real ....division... - 05-20-2004 , 11:58 AM






"=?iso-8859-2?Q?Gyenese_P=E1l_Attila?=" <gyenese (AT) mediagnost (DOT) hu> writes:
Quote:
REASON IS:

SELECT 365*10000000 ;
result: -644967296
wrong
This isn't a division problem --- the difficulty is there's no check for
overflow in int4 multiplication. (Nor in any of the other integer
arithmetic operations, for that matter.)

It'd be nice if C made it easier to detect integer overflow :-(
.... AFAIK, testing this would make those subroutines many times slower,
which is pretty annoying when the hardware already knows whether the
result overflowed or not.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Reply With Quote
  #2  
Old   
Neil Conway
 
Posts: n/a

Default Re: [BUGS] int4, int8, real ....division... - 05-21-2004 , 05:48 AM






Tom Lane wrote:
Quote:
This isn't a division problem --- the difficulty is there's no check for
overflow in int4 multiplication. (Nor in any of the other integer
arithmetic operations, for that matter.)
It seems to me that SQL2003, Section 6.26 (<numeric value expression>,
"General Rules", item 5) requires that we check for overflow after
arithmetic operations on exact numeric types:

%%%%
5) If the most specific type of the result of an arithmetic operation is
exact numeric, then

Case:

a) If the operator is not division and the mathematical result of the
operation is not exactly representable with the precision and scale of
the result data type, then an exception condition is raised: data
exception — numeric value out of range.

b) If the operator is division and the approximate mathematical result
of the operation represented with the precision and scale of the result
data type loses one or more leading significant digits after rounding or
truncating if necessary, then an exception condition is raised: data
exception — numeric value out of range. The choice of whether to round
or truncate is implementation-defined.
%%%%

Or am I misreading the spec?

-Neil


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] int4, int8, real ....division... - 05-21-2004 , 09:21 AM



Neil Conway <neilc (AT) samurai (DOT) com> writes:
Quote:
Tom Lane wrote:
This isn't a division problem --- the difficulty is there's no check for
overflow in int4 multiplication. (Nor in any of the other integer
arithmetic operations, for that matter.)

Or am I misreading the spec?
Spec compliance is not the issue here, the issue is devising a
reasonable implementation ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.