I’m building an app that graph a text given function using DDMathParser by Dave DeLong. I need to know (for every “x” I evaluate) if the solution exist, or it just gives me 0.00 because it couldn’t evaluate it. Maybe a Bool?
while (x <= (viewWidth - originOffsetX)/axisLenghtX) {
NSDictionary *variableSubstitutions = [NSDictionary dictionaryWithObject: [NSNumber numberWithDouble:x] forKey:@"x"];
NSString *solution = [NSString stringWithFormat:@"%@",[[DDMathEvaluator sharedMathEvaluator]
evaluateString:plotterExpression withSubstitutions:variableSubstitutions]];
numericSolution = solution.numberByEvaluatingString.doubleValue;
NSLog(@"%f", numericSolution);
if (newline) {
CGContextMoveToPoint(curveContext, (x*axisLenghtX + originOffsetX), (-numericSolution * axisLenghtY + originOffsetY));
newline = FALSE;
} else {
CGContextAddLineToPoint(curveContext, (x*axisLenghtX + originOffsetX), (-numericSolution * axisLenghtY + originOffsetY));
}
x += dx;
Well, since you’re using the simplest API possible, there’s no way to by notified if there’s an error. This is clearly explained in the first section of the Usage page on the wiki:
So what you want to do is this: