Arithmetical expressions <expr>

In the handling of arithmetical expressions, the general computing rules are used:

In arithmetical expressions, parameters are often used; the notation of parameters is:

Example for an arithmetical expression:

P5 = [[sin[R1*30.00] + P2] / P5]

Symbolic character sets can be assigned to arithmetical expressions and to parts thereof.

Such a string leads to the default string, which is analyzed in place of the character string. A recursive handling is also possible.

The character strings must be within quotation marks. During their decoding a differentiation is made between the upper-case and lower case letters. The nesting of strings is displayed through a pre-set '\'-character before the limiting quotation mark. Attention must be paid to the fact that always complete nesting levels are to be grouped in one string, i.e. the adding of ´[´ at the beginning and ´]´ at the end of the replacement text should not have any effect on the result of the mathematical expression.

Programming example

Correct:

N10 "STRING1" = "COS[\"STRING2\"]"
N20 "STRING2" = "5 * 12"
N30 "STRING3" = "SIN[89.5 + \"STRING1\"]"
N40 X[-2 * "STRING1" + "STRING2" + "STRING3"] (Traverse after X60)
M30

Wrong: Only complete nesting levels should be put together in the string

N10 "STRING1" = "COS["
N20 "STRING2" = "90]"
N30 "STRING3" = "\"STRING1\" \"STRING2\" "

The character sets defined in the NC-program are valid program-globally.

The programming of symbol character sets outside the mathematical expressions is described in the separate programming manual “symbolic character sets”.

Survey of all available calculation operations:

Basic types of calculation:

Addition

+

P1 = P2 + P3 + 0.357

Subtraction

-

P1 = P2 - 0.031

Multiplication

*

P1 = P2 * [P3 + 0.5]

Division

/

P1 = P2 * P3 / [P5 + P6]

Exponential calculation

**

P1 = 2**P3 (2 exponent P3)

Modulo calculation

MOD

P1 = 11 MOD 3 (-> 2)

Numerical functions:

Absolute value formation

ABS [..]

P1 = ABS [P2 - P4]

Squaring

SQR [..]

P1 = SQR [P2] + SQR [P3]

Square root extraction

SQRT [..]

P1 = SQRT [SQR[P2]+SQR[P3]]

e - function

EXP [..]

P1 = EXP [P2 * P4]

Natural logarithm

LN [..]

P1 = LN [P2] + LN [P3]

Tens - exponential

DEXP [..]

P1 = DEXP [P2]

Common logarithm

LOG [..]

P1 = LOG [P2]

Notice

In the case of LN, LOG and SQRT the argument must always be greater than 0 !

Bit operators:

AND-operation

&

P1 = P2 & P3

OR-operation

|

P1 = P2 | P3

exclusive OR

^

P1 = P2 ^ P3

Complement

INV[..]

P1 = INV[P2]

Notice

The arguments can be any positive mathematical expressions or numbers. Negative expressions or numbers are not allowed. Floating point arguments are converted to integer.

Logical operators :

logic AND operation

&& / AND

$IF P1 >= P2 && P3 != P4
respectively
$IF P1 >= P2 AND P3 != P4

logic OR operation

|| / OR

$IF P1 >= P2 || P3 != P4
respectively
$IF P1 >= P2 OR P3 !=P4

Comparison operators:

In loop constructions (see paragraph 10: "Program branches”) comparison operations will be necessary. Verifications can be done as follows:

Equality

==

$IF P1 == 5

Inequality

!=

$IF P1 != 5

greater than or equal to

>=

$IF P1 >= 10

less than or equal to

<=

$IF P1 <= 10

less than

<

$IF P1 < 10

greater than

>

$IF P1 > 10

Possible truth values are:

TRUE

true

$IF V.A.MERF.X == TRUE

FALSE

not true

$WHILE V.G.WZ[2].OK == FALSE

Notice

Use of the truth values:For TRUE control internally the value 1 is used.For FALSE control internally the value 0 is used.

Trigonometric functions (specification of angles in degrees):

Sine

SIN [..]

P1 = SIN [P2 * 30 +10]

Cosine

COS [..]

P1 = COS [P2 * 30 +10]

Tangent

TAN [..]

P1 = TAN [P2 * 30 +10]

Arc sine

ASIN [..]

P1 = ASIN [P2 * 10]

Arc cosine

ACOS [..]

P1 = ACOS [P2 * 10]

Arc tangent

ATAN [..]

P1 = ATAN [P2 * 10]

Arc tangent with 2 arguments

ATAN2 [y,x]

P1 = ATAN2[100,100]
(-> Result
is 45°)

Notice

In the case of the trigonometric functions ASIN and ACOS the argument must always be between -1 and +1.For the function TAN, the argument should not assume the values ... -90, 90, 270 ... degrees.The function ATAN2 calculates for x != 0 the angle of a position to the X axis in the correct quadrant.Exception: For ATAN2[0,0] (x = y = 0) the result is always 0.

Transformation functions:

Integer

INT [..]

cuts off the digits after the decimal point

Float

FRACT [..]

removes integer

Rounding Off

ROUND [..]

rounds off to integer

Special functions:

Check for

existence of

variables/

parameters/

M/H functions

EXIST [ <variable/parameter/

M function/ H function>]

$IF EXIST[V.P.MY_VAR] == TRUE
$IF EXIST[P1] != TRUE
$IF EXIST[M55] == TRUE
$IF EXIST[H20] == TRUE

Determine

the size of

an array

dimension

SIZEOF [<array_name>, <dimension>]

oder

SIZEOF [<array_name>] (für 1. Dim.)

$IF
SIZEOF
 [V.P.MY_ARRAY,2]
== 3
P1 =
SIZEOF[P10,2]