###############################
#include <stdio.h>
int main(void) {
double nv = 2.0 / 3;
float foo = 2.0 / 3;
if(foo == nv) printf("True ");
else printf("False ");
if(foo == (float)nv) printf("True\n");
else printf("False\n");
return 0;
}
###############################
With MSVC++ 8.0 and MSVC++ 9.0 (and the MinGW port of gcc) that
program outputs "False True" which, I believe, is both sane and
correct.
With MSVC++ 7.0, the output is "False False" which, I believe, is
neither sane nor correct.
Does anyone happen to know the workaround that will enable that
program to output "False True", irrespective of which version of the
MSVC++ compiler is used ?
Cheers,
Rob
Try the "/Op" switch, it should (I'm not completely sure how far
this extends compatibility) make vc7 behave at least somewhat
similar to vc8/9 in that regard.
In regard to sane and correct, with floats and periodic fractions
there is no such thing :)
-Chris