Informations for hEvaluate.h

Purpose

To have informations on what the header is capable of doing just follow this link.

How to use the functions in the expression

In the expressions entered as argument of the Solve function you can use these operators: +, -, *, /, ^.
Numbers can be entered both as not decimal or decimal and even in exponential form.

The functions allowed at the moment are:
sine: double sin(double argument)
cosine: double cos(double argument)
tangent: double tan(double argument)
Inverse sine: double asin(double argument)
Inverse cosine: double acos(double argument)
Inverse tangent: double atan(double argument)
Hyperbolic sine: double sinh(double argument)
Hyperbolic cosine: double cosh(double argument)
Hyperbolic tangent: double tanh(double argument)
Secant: double sec(double argument)
Cosecant: double csc(double argument)
Cotangent: double cot(double argument)
Exponential: double exp(double argument)
Natural logarithm: double ln(double argument)
Logarithm in a chosen base: double log(double argument)
Square root: double sqrt(double argument)
Root with a chosen index: double rt(double argument)
Absolute value: int abs(double argument)

Sources informations

The actual vesion is the 2.2.
Here you can have informations on how to use the hEvaluate.h header in your programs and various technical specifications on the several functions it offers.

How to use the solver

The main function present in hEvaluate is the function Solve:
int Solve (char sExpression[], short int &iErrorPosition, short int &iErrorType);

Parameters sExpression[] is the string which contains the expression to be evaluated. The string must have the terminator at the end. The variable, if a valid expression, will be replaced by the result.

iErrorPosition is a variable, passed by address (so modifiable). It will contain the position of the first eventually found error. If no error is found, the variable will remain unchanged.

iErrorType is a variable passed by address which will contain the code to describe the error found (if found).

-1 -- A general syntax error has been found (ex. "**").

-2 -- The operation 0/0 has been found during the parsing.

-3 -- The operation n/0 (with n belonging to the reals) has been found during the parsing.

-4 -- A not recognized function has been found.

-5 -- Error computing the function asin(double). The argument must be comprised between -1 and 1.

-6 -- The same as in -5, but in this case the error is in the function acos.

-7 -- Error found during the computing of a logarithm. The argument must be grater than 0.

-8 -- Error found during the computing a a logarithm, the base must be grater than 0 and different from 1.

-9 -- Found a aquare root of a negative number. The dominion is for each "not negative" x.

-10 -- Error found during the computing of a root with peer index with a negative argument. This error is very similar to the previous one but it's not the same. This refers to the function rt(double base, double argument) whereas the previous refers to the function sqrt(double argument). In this way it is even possible to differentiate between the two cases if needed.

Returned value The value return is an integer and can be 0 or 1. If it is 0 then at least one error has been found, otherwise no error has been found.

If the returned value is 0 then you can use the last two variables to understand what has gone wrong. If the returned value is 1 the last two variables have not been modified.

Complete functions reference

int Solve (char sExpression[], short int &iErrorPosition, short int &iErrorType);
Already expleined above.
int Evaluate (char sExpression[], short int &iErrorPosition, short int &iErrorType);
This function can solve an expression without parenthesis. The arguments are the same of those used by the Solve function.
int CheckExpression (char sExpression[], short int &iErrorPosition);
The CheckExpression can check the presence of some not allowed syntaxes. If an error is found than iErrorPosition will contain the position of the error in the vector. sExpression is a vector containing the expression to be checked.
bool CheckSeparator (char sExpression[]);
The CheckSaperator function is able to determine whether in the expression passed as a string, a separator is present. A separator is the character ",", which is used in some functions to separate two parameters. This function is used inside the parsing process to understand if a simplified expression mast be re-inserted inside its parenthesis (because containing arguments of a function) or not.
bool CheckOperator (char sExpression[]);
The CheckOperator can determine if in the expression passed there is unless one operator. CheckOperator is able to understand the difference between a operator and a symbol intended as a sign like (+2). sExpression is obviously the expression to be checked.
void ReplaceString (char sExpression[], char sNewString[], int iStart, int iEnd);
ReplaceString can be used to replace the elements present in sExpression from iStart (comprised) to iEnd (not comprised) with the elements of the string sNewString. Both sNewString and sExpression must be zero termiinated. iStart is the first element which will be substituted. The element in position iEnd wil not be sobstituted.
void SortParenthesis (char sExpression[]);
SortParenthesys fills the parenthesis structure with informations regarsing the position of open and close parenthesis in the expression passed with sExpression.
bool IsNumber (char sExpression[], int iSymbolPosition, bool bConsiderPoint, bool bConsiderExponential);
IsNumber returns true if the character in position iSymbolPosition in the vector sExpression is a number. Otherwise the returned value is false. The value bConsiderPoint must be set to true if you want the function to consider the point (as decimal separator) as part of the number. The bConsiderExponential is not yet foreseen, but is handled by the other functions.
bool IsLetter (char sExpression[], int iSymbolPosition, bool CheckE);
IsLetter return true if the element in iSymbolPosition of sExpression is a letter, otherwise the returned value id false. The CheckE variable must be set to true if you want to handle exponential numbers.
void EvaluatePowers (char sExpression[]);
Evaluates all the powers found in the given expression. No returned value is present.
int EvaluateMultiplications (char sExpression[], short int &iErrorPosition, short int &ErrorType);
Evaluates alla the multiplications and divisions present in sExpression. If a n/0 or 0/0 is found, then the returned value is false. In this case iErrorPosition and ErrorType will be used. iErrorPosition will be the position of the first element belonging to the error. ErrorType is needed to distinguish the difference between 0/0 and n/0. If no error is found the returned result is true.
void EvaluateAdditions (char sExpression[]);
Computes all the additions and differences.
int EvaluateFunctions (char sExpression[], short int &iErrorPosition, short int &iErrorType);
The EvaluateFunction evaluates every function in the expression given. The returned value is true if no error is found, otherwise the returned value is false. In case it is false, iErrorPosition and iErrorType will contain the position of the error and the type of error. For the error code see the table above.
double FindOperator (char sExpression[], int iSymbolPosition, char cLastSymbol, bool bFindFirst);
FindOperator can find the operand after or befor the operator. iSymbolPosition is the position of the operator, last symbol is the last simbol of the operator (or of the function). bFindFirst must be set to true if you want the first operator, set to false if you want the second. The returned value is the operator.
int FindFunction (char sExpression[], int iStart);
FindFunction can be called to understand if in position iStart there is a known function. If a function is found then its code will be returned.

Download informations

Download the hEvaluate header (.zip format)