I have to check a float variable to determine the existence of a particular variable. Ideally it should have been a bool value or at least an int. Because of interface constraints and legacy code I am not able to change the data type to bool. So if I've to make a check, can I directly do it as shown below in the sample code:
void check(float f)
{
if (!f)
printf ("Zero val!\n");
else
printf ("Value exists!\n");
}
Would it be fool proof Or is there be a better way to do it, considering the fact how the value is stored in a float variable. Casting it to an short and checking is out of the game because : If the value is '1' it is stored as 0.9999998; casting it to a short would result in a '0' which is wrong.
P.S The code happens to be present in a Objective C file, but in the C format.