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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -