erroneous Visual C float / double conversion?
- by RED SOFT ADAIR
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.