How to calculate formulas like (a + b) ^ 2, sum((a + b) / 2)
using NSExpression
? I am the beginner to NSExpression
.
(a + b) ^
NSExpression is used to represent expressions in NSPredicate. It is not intended for the tasks like yours.
Actually, you can use NSExpression
to calculate the formula value, but this usage is quite limited. To evaluate any mathematical expression you would need to make a string parser using some algorithm i.e. Shunting-yard or just reuse a library like this one.