Brenda Bowers

Greenhorn
+ Follow
since Sep 17, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Brenda Bowers

Thanks Jim & Greg.
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.