私は NSNumber の NSMutableArray を扱っていて、奇妙なバグに遭遇しました。[NSNumber doubleValue] (ダブル 0 のコンストラクト) は 0.0 に等しくないようです。
このバグは、これまでで最も単純な関数である max 関数に現れます。
- (double) maxValY{
double max = DBL_MIN;
for (NSNumber *doubleNumber in arrayNumbers) {
if (max<[doubleNumber doubleValue]){
max = [doubleNumber doubleValue];
}
}
NSLog(@"max %f",max);
if(max <=0.0){
NSLog(@"max is equal to 0");
return 1;
}else{
NSLog(@"max is not equal to 0");
}
return max;
}
コンソールに次のように出力されます。
2013-01-02 11:27:56.208 myApp[1920:c07] max 0.000000
2013-01-02 11:27:56.210 myApp[1920:c07] max is not equal to 0