FUNCTION: CALC

STUB: result_value = CALC( expression )


where expression can be a mathematical expression that refers to other vectors. Any references to previously calculated vectors should be explicit (i.e., referred to as CLOSE(0), CLOSE(1) or MA20(5)) and not with an index of i (as is the case with function LOOPCALC).

Please note that explicit references to an entry of a vector should start with 0 (zero) and not 1.

You can also use negative numbers for refering to an entry. For example, CLOSE(0) refers to the oldest value in the vector, CLOSE(1) refers the second oldest, etc. But because most of the time you need your formulas to work from day to day without requiring you to change the formula, you can use values such as CLOSE(-1) to refer to the latest value, CLOSE(-2) to refer to the second latest, etc. You may also use the expression CLOSE(SIZE-1) to refer to the last value of vector CLOSE. SIZE is the size of the matrix and therefore the size of each vector, since all vectors have the same length. Please remember though the elements in a vector are accesses from 0 to SIZE-1. So, in the case of a vector called CLOSE this will be CLOSE(0), CLOSE(1), CLOSE(2),..., CLOSE(SIZE-1). For the record, please note than CLOSE(-1) and CLOSE(SIZE-1) refer to the same value.

Please note that CALC returns a single value whereas LOOPCALC returns a vector.

Example:    

Rank1 = CALC ( 10 + 2)
Rank2 = CALC ( CLOSE(0) )



The following are valid expression operators:

Symbol  Equivalent  Description                Example

( )                 Prioritizes an expression  5*(1+1) = 10
            
!       Fact        Factorial                  5! = 120
                                               fact(5) = 120
%                   Percentage                 35% = 0.35
^       **          Raised to the power of     4 ^ 5 = 1024
*                   Multiply by                3 * 6 = 18

/                   Divide by                  9 / 2 = 4.5
\       div         Integer divide by          9 \ 2 = 4
mod     %           Modulo (remainder)         7 mod 4 = 3
+                   Add                        1 + 1 = 2
-                   Subtract                   9 - 5 = 4

+                   Unary plus                 +5     = 5
-                   Unary negation             -(5+4) = -9
            

>                   Greater than (numeric)     9 > 2 = 1
<                   Less than (numeric)        7 < 4 = 0
==      =           Equal test (numeric)       5 == 4 = 0
>=                  Greater or equal (numeric) 3 >= 3 = 1
<=                  Less or equal (numeric)    #h3E <= 9 = 0
                  Not equal (numeric)        #b10101  20 = 1

Please note that the above relational operators
(>, <, <=, >=, ==, ) return a 1 (for true) or a 0 (for false)

>                   Greater than (string)      'This' > 'That' = 1

<                   Less than (string)         'This' < 'That' = 0
==      =           Equal test (string)        'A' == 'B' = 0
>=                  Greater or equal (string)  'Zeb' >= 'Zebra' = 0
<=                  Less or equal (string)     'Zeb' <= 'Zebra' = 1
                  Not equal (string)         'X'  'Y' = 1
+       &           Concatenate                'Zeb' + 'ra' = 'Zebra'
            
Not                 Bitwise NOT                NOT 15  = -16

And                 Bitwise AND                #b101 AND #h1E = 4
Or                  Bitwise OR                 13 OR 6 = 15
Xor                 Bitwise Exclusive OR       9 XOR 3 = 10
Eqv                 Bitwise Equivalence        6 EQV 9 = -16
Imp                 Bitwise Implication        1 IMP 5 = -1
            
IIf                 If condition               IIf(1+1=2,4,5) = 4
Min                 Minimum value              min(10,3,27,15) = 3

Max                 Maximum value              max(1,9) = 9 *see note
            
Sin                 Sine                       sin(pi) = 0
Cos                 Cosine                     cos(pi) = -1
Tan                 Tangent                    tan(pi) = 0
Asin                Arc sine                   asin(1) = 1.570
Acos                Arc cosine                 acos(-1) = 3.141
Atan    Atn         Arc tangent                atan(0) = 0

Sec                 Secant                     sec(0) = 1
Csc                 Cosecant                   csc(1) = 1.18
Cot                 Cotangent                  cot(1) =  0.642
            
Sinh                Hyperbolic sine            sinh(3) = 10.01
Cosh                Hyperbolic cosine          cosh(2) = 3.76
Tanh                Hyperbolic tangent         tanh(1) = 0.76
Coth                Hyperbolic cotangent       coth(1) = 1.31

Sech                Hyperbolic secant          sech(0) = 1
Csch                Hyperbolic cosecant        csch(1) = 0.85
Asinh               Hyperbolic arc sine        asinh(2) = 1.44
Acosh               Hyperbolic arc cosine      acosh(9) = 2.89
Atanh               Hyperbolic arc tangent     atanh(.1) = 0.10
Acoth               Hyperbolic arc cotangent   acoth(7) = 0.14
Asech               Hyperbolic arc secant      asech(.3) = 1.87

Acsch               Hyperbolic arc cosecant    acsch(2) = 0.48
            
Abs                 Absolute value             abs(-8) = 8
Exp                 e to the power of          exp(3) = 20.08
Exp2                2 to the power of          exp2(3) = 8
Exp10               10 to the power of         exp10(3) = 1000
Log     Ln          Natural log                log(16) = 2.77
Log2                Log base 2                 log2(8) = 3

Log10               Log base 10                log10(100) = 2
Ceil                Round up                   ceil(6.2) = 7
Rnd                 Random number              rnd(1) = .969
Int                 Truncate to an integer     int(6.8) = 6
Sgn     Sign        Sign (returns -1, 0, or 1) sgn(-9) = -1
Sqr     Sqrt        Square root                sqr(64) = 8


The MIN and MAX functions accept up to 6 input values.

The definition for the IIF function is as follows:  IIF(condition, true, false).  If the value of condition is true, then the true expression is evaluated and returned, otherwise false is evaluated and returned.