Thanks for helping, Mokargas! I like you!!
I was excited to find the NSPredicate solution but unfortunately, it yields wrong calculations when it's division and the dividend and divisor are both integers, for example:
NSString *str7 = @"((10+(25/22))*10)"; // shd be 111.36364, not 110
NSString *str8 = @"((10+(25/22))*10.111)"; // shd be 112.59977, not 111.221
NSString *str9 = @"((10+(25/22.0))*10.111)"; // the fix to get 112.59977
NSString *equation = @"1+5*6";
// dummy predicate that contains our expression
NSPredicate *pred = [NSPredicate predicateWithFormat:
[equation stringByAppendingString:@" == 42"]];
NSExpression *exp = [pred leftExpression];
NSNumber *result = [exp expressionValueWithObject:nil context:nil];
NSLog(@"%@", result); // logs "31"
Apparently the float result is always converted to integer. So for workaround, I replaced the string's occurrences of @"/" with @"*1.0/" though I'm not sure that is a reliable solution.
Few days ago I came across a short doc on Tcl Math Library, that mentioned a linear algebra pkg, like below:
This manual page is for Mac OS X version 10.6.6
…
…
math(n) Tcl Math Library
NAME
math - Tcl Math Library
SYNOPSIS
package require Tcl 8.2
package require math ?1.2.4?
//... text edited out…
• math::geometry - 2D geometrical computations
• math::interpolate - Various interpolation methods
• math::linearalgebra - Linear algebra package
• math::optimize - Optimization methods
//... text edited out…
The thing is I have no idea if I can use this Tcl math lib for an iPhone app, nor do I know how to find this lib. I'm also wondering it has a good docu about that linear algebra.