erroneous Visual C float / double conversion?
Posted
by RED SOFT ADAIR
on Stack Overflow
See other posts from Stack Overflow
or by RED SOFT ADAIR
Published on 2010-04-07T08:53:23Z
Indexed on
2010/04/07
9:13 UTC
Read the original article
Hit count: 281
In Visual C++ i wrote the following sample in a C++ program:
float f1 = 42.48f;
double d1 = 42.48;
double d2 = f1;
I compiled the program with Visual Studio 2005. In the debugger i see the following values:
f1 42.480000 float
d1 42.479999999999997 double
d2 42.479999542236328 double
d1 by my knowledege is OK, but d2 is wrong.
The problem occurs as well with /fp=precise as with /fp=strict as with /fp=fast.
Whats the problem here? Any hint how to avoid this Problem? This leads to serious numerical problems.
© Stack Overflow or respective owner