I declared a=0.7,but when I checked with if else it goes to statement a<0.7,why?
a=0.7 resolves to a<0.7?
Collapse
X
-
You don't post your if/else statement.
I suspect you are running into rounding.
You should compare your floating point numbers +/- using an allowable precision:
Code:if ( (a - .000001) < 0.7) etc...
-
Read what every computer scientist should know about floating-point arithmetic.
By the way, a better way to compare floating-point numbers for equality within a precision threshold is more like this:
Refer to C FAQ 14.5 for the best way to do it.Code:if (fabs(variable - desiredValue) < threshold) ...
Comment
Comment