PIP
0.4.0_beta2
Platform-Independent Primitives
|
This class provide mathematical evaluations of custom expression. More...
Public Member Functions | |
PIEvaluator () | |
Constructs an empty evaluator. | |
void * | data () |
Returns custom data. | |
void | setData (void *_data) |
Set custom data to "_data". | |
bool | check (const PIString &string) |
Check mathematical expression and parse it to list of instructions. | |
bool | isCorrect () const |
Returns true if expression was checked succesfully. | |
int | setVariable (const PIString &name, complexd value=0.) |
Set variable value with name "name" to value "value". Add variable if it doesn`t exists. | |
void | setVariable (int index, complexd value=0.) |
Set variable value with index "index" to value "value". Dont add variable if it doesn t exists. | |
complexd | evaluate () |
Evaluate last successfully checked with function check() expression and returns result. | |
void | removeVariable (const PIString &name) |
Remove variable with name "name". | |
void | clearCustomVariables () |
Remove all manually added variables. | |
int | variableIndex (const PIString &name) const |
Returns index of variable with name "name". | |
const PIStringList & | unknownVariables () const |
Returns all unknown variables founded in last expression passed to check() function. | |
const PIString & | expression () const |
Returns processed last expression passed to check() function. | |
const PIString & | error () const |
Returns last error description occured in check() function. | |
const complexd & | lastResult () const |
Returns last result of evaluate() | |
This class provide mathematical evaluations of custom expression.
PIEvaluator developed for stream evaluations of once set expression. It`s create internal list of instructions on function check() and executes very fast on function evaluate(). Once given expression can be evaluated any times with different variable values. Evaluator supports many common mathematic functions described below. Also it`s automatic puts unnecessarily signs and bracets. Processed expression can be obtains with function expression(). If there is an error in expression you can get it with function error(). Last evaluated result you can get with function lastResult().
First you should set your variables with function setVariable(). Next give your expression with function check() and check for error with functions isCorrect() and error(). If expression is correct you can get processed expression with function expression() and evaluate it with function evaluate(). You can change variable values without rechecking expression.
PIEvaluator supports arithmetical operations with complex numbers, this is their list in priority order:
In addition there are compare and logical operations:
Compare and logical functions works with real operators part and returns 0 or 1.
Mathematical functions:
There are some built-in constans:
All trigonometric functions takes angle in radians.