DDMathParser: nil value

80 Views Asked by At

Sorry for my english, I try to explain better my problem: I need to parse a math expression and then save the results inside a variable, this is my code:

for (i = -100; i < 100; i = i + step) {
    NSError *error = nil;
    NSDictionary *variableSubstitutions = [NSDictionary dictionaryWithObject:[NSNumber numberWithDouble:i] forKey:@"x"];
    NSNumber *y = [[DDMathEvaluator sharedMathEvaluator] evaluateString:[self convertString:eq.equazione] withSubstitutions:variableSubstitutions error:&error];
    NSLog(@"y is: %@",y);
}

The NSLog have always a value, if I try to parse an expression like tan(x) the log never print a nil value, I need to display also the nil value if exist. I try to check y value, error value but I don't find a way for handle nil value of expression.

1

There are 1 best solutions below

0
On

This is probably not what you want, if not please update your question.

NSNumber *y = [[DDMathEvaluator sharedMathEvaluator] evaluateString:[self convertString:eq.equazione] withSubstitutions:variableSubstitutions error:&error];
if(y)
    NSLog(@"y is: %@", y);
else
    NSLog(@"y is: nil");