Subj : Re: Serious Problem with precision or if statement To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Fri Aug 15 2003 04:54 pm José J. Armenta E. wrote: >, and the solution >I found to this issue was to use a variable instead a constant, >as in the following code: > >int main() > { > int Phase = 3; > double d=3; > if(Phase/d == 1.0 ) > printf("equal"); > else > printf("not equal"); > return 1; > } > >Using this workaround yield the expected result when compiled with >the IDE or the command line (16/32 bits). Ideally, you don't use integers when you really want floats. You use integers when you are going to do integer calculations, and floats when you are going to do floating point calculations. int main() { int phase1 = 3; float Phase2 = 3.0; if(Phase1/3 == 1 ) printf("phase1"); if(Phase2/3.0 == 1.0 ) printf("phase2"); return 1; } And, of course, floats aren't always exactly the value you expect. Integers are superior in that reguard. .