Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

float == double conditionality, pre-VC 8.0

0 views
Skip to first unread message

sisyphus

unread,
Jul 18, 2009, 3:11:00 AM7/18/09
to
Hi,
The demo script:

###############################
#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

Christian Winter

unread,
Aug 5, 2009, 3:22:43 PM8/5/09
to

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

0 new messages