This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/14788] [3.3/3.4/3.5 Regression] Subtracting a double from a short gives incorrect result


------- Additional Comments From wilson at specifixinc dot com  2004-03-31 00:11 -------
Subject: Re:  [3.3/3.4/3.5 Regression] Subtracting a double
 from a short gives incorrect result

Not a bug.

The double subtract results in a value -35536.0 which exceeds the range 
of short.  So the result of the second subtraction depends on the 
behaviour of converting an out-of-range value to a short, which is 
undefined.  So both gcc and the Sun compiler are correct here.  Any 
result is correct here.  Gcc is converting the value to SHRT_MIN which 
is the closest representable short value.  The Sun compiler is perhaps 
converting to int and then truncating to short which gives a wrapped 
around result.

This is section 3.2.1.3 in the 1989 ANSI C standard, and section 6.3.1.4 
in the 1999 ISO C standard.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14788


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]