This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/14788] [3.3/3.4/3.5 Regression] Subtracting a double from a short gives incorrect result
- From: "wilson at specifixinc dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 31 Mar 2004 00:11:44 -0000
- Subject: [Bug target/14788] [3.3/3.4/3.5 Regression] Subtracting a double from a short gives incorrect result
- References: <20040330215205.14788.rick@glentng.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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