Re: Casting double to int produces inconsistent results from VS 2003 to VS 2008
- From: "Anthony Wieser" <newsgroups-sansspam@xxxxxxxxxxxxxxxxxxx>
- Date: Sun, 29 Mar 2009 07:52:55 +0100
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@xxxxxxxxxxxxxxx> wrote in message news:OWCOGQBsJHA.3648@xxxxxxxxxxxxxxxxxxxxxxx
KD wrote:I am porting some legacy code from VS 2003 to VS 2008, and I've
encountered a problem. Here is an example to illustrate:
{
double f = 10000000000.0;
int d = (int) (f);
}
When I run from VS2003, I get:
d = 1410065408
When I run from VS2008, I get:
d = -2147483648
Can someone please explain why d2 is different in VS 2008?
I suspect that the difference appeared in VS2005 when there was major work done on the back end for floating point code generation (both for corectness and performance). It's not surprising that an undefined case like this is apparently handled differently. You might experiment with the /fp options, particularly /fp:fast, which IIRC most closely approximates the model used in previous versions of the compiler.
-cd
If you compile with warning level 4, do you get warnings under both compilers?
Anthony Wieser
Wieser Software Ltd
.
- References:
- Casting double to int produces inconsistent results from VS 2003 to VS 2008
- From: KD
- Re: Casting double to int produces inconsistent results from VS 2003 to VS 2008
- From: Carl Daniel [VC++ MVP]
- Casting double to int produces inconsistent results from VS 2003 to VS 2008
- Prev by Date: Re: Casting double to int produces inconsistent results from VS 2003 to VS 2008
- Next by Date: Re: Casting double to int produces inconsistent results from VS 2003 to VS 2008
- Previous by thread: Re: Casting double to int produces inconsistent results from VS 2003 to VS 2008
- Index(es):
Relevant Pages
|