Why are duplicates not added correctly to a specific Visual Studio 2008 project?

Trying to port java code to C ++ I came across some strange behavior. I cannot get a double complement to work (even if the compiler option is / fp: strict, which means that the “correct” floating-point math is set in Visual Studio 2008).

double a = 0.4;
/* a: 0.40000000000000002, correct */

double b = 0.0 + 0.4;
/* b: 0.40000000596046448, incorrect
(0 + 0.4 is the same). It not even close to correct. */

double c = 0;  
float f = 0.4f;  
c += f;
/* c: 0.40000000596046448 too */

In another test project that I set up, it works fine (/ fp: strict behaves according to IEEE754).

Using Visual Studio 2008 (standard) without optimization and FP: strict.

Any ideas? Does it truncate swimming? This project really requires the same behavior on the Java and C ++ side. I got all the values ​​by reading from the debug window in VC ++.

: _fpreset();// . FP .

+5
2

, , , , DLL, .

_fpreset() float.h ?

+8

, , , . float f = 0.4, "". :

double b = 0.0 + (double) 0.4;

, . 0.0 + 0.4 , , , .

, - , , .

+3

All Articles