AlgebraicExpressionCalculate

Algebraic Expression Calculate

Minor Business Rule

Object Name: B0000500

Parent DLL: CALLBSFN

Location: Client/Server

Language: C

1.Functional Description

1.1Purpose

This business function calculates the algebraic expression in a string and return a mathnumeric value 

if the return code is SUCCESS, otherwise return error message ID.




1.2Setup Notes and Prerequisites


The Input  string format:

• 

May or may not contain parentheses to establish precedence.
• May or may not contain blank(s)
• May not contain character string other than arithmetic functions. 
• All arithmetic function characters must be in upper case, 
The input string is a 501-upper-case-character string.


Available arithmetic functions:

• 
ABSAbsolute sign value to positive value
• INTRound off to integer
• SGNChange sign of value
• SQRSquare root
• **Exponent
• LNNatural Logarithm
• LOGLogarithm base 10
• COSCosine
• SINSine
• TANTangent
• ARCArc Tangent


1.3Special Logic


A.Delimiters:
The following delimiters are prioritized as:

1)')'Right parentheses
2)'/'Division

3)'*'Multiplication

4)'-'Minus

5)'+'Addition

6)'('Left parentheses



2.Technical Specifications

2.4Processing 



A.Parentheses:

Scan through input string for quick inspection on parentheses.  Parenthesis must go 

in pair and each left parenthesis must has a right parentheses.  If the parentheses 

is improperly place,  skip all steps below and return ERROR status.



B.Characters:
Scan through input string for inspection on characters.  There should not be any character or string 

other than function names that defined in section 1.2.  If there is any invalid character or string, 

skip all steps below and return ERROR status.



C.Evaluation:

Perform evaluation of delimiters in prioritized order as defined in section 1.3 

1) Arithmetic functions (evaluate the value in the parentheses first.)
2) Algebraic expression in the parentheses.

3) Algebraic expression string



D.Return:
If there is any error during evaluation,  return ERROR status.

Else return SUCCESS status and result.





3. Examples


2+3-4*5/6  =>  2+3-20/6 =>2+3-3.33333 = 1.66667


2+(3-4)*5  =>  2-1*5 = -3


(2+(3-4)*5)**(8-6) =>  (2-1*5)**(8-6)  =>  (-3)**2  =  9


(1+ABS(COS(3.1416)))/(2+1)-5  => (1+ABS(-1))/(2+1)-5  

=> (1+1)/(2+1)-5  => 2/(2+1)-5  =>  2/3-5  => .66666 -5  =  -4.33334

Data Structure

D0000500 - Algebraic Expression Calculate

Parameter NameData ItemData TypeReq/OptI/O/Both
szAlgebraicExpressionStringCALCITcharNONENONE

 This field is used to store an algebraic expression string

mnCalculatingResultMN29D9MATH_NUMERICNONENONE

This is a generic field used as a work field in Everest.

cSuppressErrorMessageEV01charNONENONE

An option that specifies the type of processing for an event.

szErrorMessageIDDTAIcharNONENONE

A code that identifies and defines a unit of information. It is an alphanumeric code up to 8 characters long that does not allow blanks or 
special characters such as %, &, or +. You create new data items using system codes 55-59. You cannot change the alias.

Related Functions

None

Related Tables

None