I’m trying to do some math in an Objective C method, and I’m totally at a loss as to why it’s not working. Here is the code:
-(IBAction)moreSetup:(id)sender{ // Connected to the Curved Average Slider
NSLog(@"%@",avgScore);
NSLog(@"%@",[avgScore class]);
NSLog(@"%@",curvedAvg);
NSLog(@"%@",[curvedAvg class]);
NSLog(@"%@",maxScore);
NSLog(@"%@",[maxScore class]);
NSLog(@"%@",[NSNumber numberWithFloat:(maxScore - curvedAvg)]);
NSLog(@"%@",[NSNumber numberWithFloat:(maxScore - avgScore)]);
// self.minCrvdStdDev = ((maxScore - curvedAvg)/(maxScore - avgScore)) * stdDev;
// NSLog(@"CS=%@ max=%@ CA=%@ AveScore=%@ stdDev=%@",minCrvdStdDev,maxScore,curvedAvg,avgScore,stdDev);
// self.curvedStdDev = minCrvdStdDev;
// [self getCurved:sender];
}
…and here is the log:
First thing, how come I need to use “numberWithFloat” to get this to work, since the two number I’m subtracting are NSNumbers or NSCFNumbers (if I don’t put in that in, I get an EXC_BAD_ACCESS error, and I can leave it out if I use %f instead of %@).
Secondly, how come 92-78 = -331040?
I guess my larger question is, what is the best way to do math in Objective C? I have numbers going in and out of dictionaries, so those need to be NSNumbers, but I also need to do various math operations on these numbers.
Ric