xcode - Impossible to achieve certain float value -
xcode - Impossible to achieve certain float value -
i testing code. have boolean conditions float numbers.
i assign float value test code:
float testfloatvalue = 0.9; and boolean status not met:
if (testfloatvalue == 0.9) { } because when debugging, float number has changed 0.9 0.899999976
i not understand anything!
due nature of floating point numbers values not possible represented exactly. never want direct check equality... there numerous articles on web , if search find many. here quick routine can utilize in objective c check equal.
bool arealmostequal(double result, double expectedresult) { homecoming fabs(result - expectedresult) < .0000000001; } you utilize per values in original question:
if(arealmostequal(testfloatvalue, 0.9) { // } xcode floating-accuracy
Comments
Post a Comment