Mathematical Operators

Built In Operators:

The following is a list of all built in operators available in mathematical expressions. All words (e.g. mod or AND) are case insensitive.

 

Symbol

Description

Example Expression

Result

()

Prioritizes an expression

5*(1+1)

10

!

Factorial

5!

120

%

Percentage

35%

0.35

^

Raised to the power of

4^5

1024

**

Raised to the power of

4.00E+05

1024

*

Multiply by

3 * 6

18

/

Divide by

2 / 9

4.5

\

Integer divide by

9 \ 2

4

mod

Modulo (remainder)

7 mod 4

3

+

Add

1+1

2

-

Subtract

9 - 4

5

>

Greater than * see note

9 < 2

1

<

Less than

9 < 2

0

==

Equality test

5 == 4

4

>=

Greater or equal

3 >= 3

1

<=

Less than or equal

4 <= 3

0

<>

Not equal

5 <> 4

1

NOT

Logical (Bitwise) NOT

NOT(15)

-16

AND

Logical AND

13 AND 6

4

&

Logical AND

13 & 6

4

OR

Logical OR

13 OR 6

15

|

Logical OR

13 | 6

15

XOR

Logical Exclusive OR

9 XOR 3

10

EQV

Logical Equivalence

6 EQV 9

-16

IMP

Logical Implication

1 IMP 5

-1

* NOTE: All relational operators (>, <, ==, >=, <=, <>) return 0 if false and 1 if true

 

In general, all the modules using mathematical operations follow the general syntax rules of Visual Basic (left to right evaluation, case insensitive syntax), with the following enhancements:

 

Implicit Multiplication:

When multiplication is implied, the times symbol (*) can often be omitted, as in the following examples:

x y = x*y

3pi + 10 = 3*pi + 10

5(4+8) = 5*(4+8)

(5+5)(3+9) = (5+5)*(3+9)

(3+2)8 = (3+2)*8

 

Note: Implicit multiplication has the same priority as regular multiplication. For instance '1/2q' is translated as '1/2*q' not '1/(2q)'. This is subject to change in future versions. To avoid such ambiguity, the multiplication symbol (*) should be used explicitly as much as possible.

 

Numeric Bases:

Binary, octal, and hexadecimal numbers can be used in all math expressions. These numbers must be preceded by the character # followed by b, o, or h for binary, octal, or hexadecimal. Numbers may include a floating point. For example:

452 = #h1C4

452 = #o704

452 = #b111000100

#o704 = #h1C4

 

Order of Precedence:

When multiple operators and functions occur in a single expression, each individual part is evaluated in the following order:

 

Anything inside parenthesis is performed first

Factorial, percentage !, %

Exponentiation ^

Negation (unary) -

Multiplication, division *, /

Integer division \

Modulo (remainder) MOD

Addition, subtraction +, -

Relational operators <, >, >=, <=, =, <>

AND operator

OR, XOR (exclusive or)

EQV (equivalence)

IMP (implication)

 

When consecutive operators have the same priority, they are evaluated from left to right. This means that an expression such as "a-b-c" is evaluated as "(a-b)-c".

 

Functions:

The following functions can be used to perform mathematical and logical operations:

Function

Description

Example of Use

Result

IIF

If condition

IIf(1+1=2,4,5)

4

MIN(a, b, c, etc) *

Minimum value

min(10,3,27,15)

3

MAX(a, b, c, etc) *

Maximum value

max(1,9)

9

CLAMP

Clamp between two values

clamp(1,4,100)

4

INTERP *

Interpolate between values

Interp(0,10,0.3)

3

INTERPLOG *

Interpolate between log values

Interplog(0,2,.5)

1.7

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.14159

ATAN or 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

POW

Raise base to exp

pow(10,3)

1000

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 or 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

ROUND

Rounding function

Round(588026.07,-4)

590000

Round(588026.07,-2)

588000

Round(26.07623,2)

26.08

RND

Random number

rnd(1)

0.969

INT

Truncate to an integer

int(6.8)

6

SGN or SIGN

Sign of expression(-1, 0, or 1)

sgn(-9)

-1

SQR or SQRT

Square Root

sqr(64)

8

NOTES:

 

Variables:

The following variables can be used to perform mathematical and logical operations:

Pi = 3.14159265358979323

E = 2.718281828

 

User defined variables and functions:

The end user now can define their own functions and variables to use in mathematical expressions. C Tech has defined many conversion functions as examples, which can be found in the file data\special\CTechFunctions.math. You can define your own macro functions and variables to use in the file data\special\UserFunctions.math. See these files for examples of use. All samples provided will be available for use in any mathematical expression.

© 1994-2018 ctech.com