could somebody explain why the following code gives "invalid" as the output?
// code
float w=2.3;
if(w==2.3)
puts("valid");
else
puts("invalid");
//********
when I tried the same with double datatype, it worked!!!
It also worked when I changed the if statement to
if(w==2.3f)
puts("valid");
else
puts("invalid");



LinkBack URL
About LinkBacks



This used to be true for older computers, but now math co-processors are pretty much on every new machine. So floating point math can sometimes be faster than integer math. Forget about performance until there is a real need and just use what best suits the problem. But be aware of the problems that floating point calculations can create.