float comparison problem objective c
strange behav开发者_如何学运维ior:
(xcode 4 breakpoint screenshot)
why does this comparison yield true? I really dont get it..
The code seems to be working correctly,
are you sure the comparison validates true?
Quick snippet:
for(int i=0;i<10;i++){
float value = (arc4random()%100)/(float)100.0f;
NSLog(@"%f",value);
if(value < 0.01f) {
NSLog(@"YES");
} else {
NSLog(@"NO");
}
}
Output:
0.520000
NO
0.520000
NO
0.100000
NO
0.000000
YES
0.390000
NO
0.690000
NO
0.770000
NO
0.930000
NO
0.320000
NO
0.230000
NO
EDIT - Response to comment:
In my case, the breakpoints are working correctly:
精彩评论