From the sample
test of Bill Brogden's Exam Cram, I compiled and ran the following :
float A = 1.0F / 3.0F;
if ( (A * 3.0F) == 1.0F )
System.out.println("Equal");
else System.out.println("Not Equal");
and I got "Equal" printed.
But the answer is "Not Equal". The reason given is a floating-point number cannot exactly represent the fraction 1/3 -- multiplying by 3 does not recover the original number. I think the explanation makes sense. Could anybody help me understand why I got "Equal"?
Thanks.