7.8.12.6. Mathematical functions (feature algorithm )

[Note]Note

Functions may occur in conditions and allocations of numerical variables.

Example condition:

IF (L1.LT.SQRT(25)) THEN ...

Examples Assignment of number variables:

D3=LOGL1

A=(B+5)*3-10/2

C=SQRT(A**2+B**2)

Conditions

IF () THEN
  VAR = 
ELSE
  VAR = 
ENDIF

Commands:

  • IF (....): Enter the condition between the brackets () (e.g. "<Variable>.EQ.10").

  • THEN: After THEN <variable> =, enter the value that the variable should assume if the condition is met.

  • ELSE ...: After ELSE <variable> = is the value for the variable if the condition is not met.

  • ELSEIF (....): Between IF and ELSE, any number of distinction of cases can be added.

    [Note]Note

    ELSEIF loops have to be ended by an ELSE.

  • ENDIF: End of condition.

Examples with values:

IF (L1.EQ.10) THEN
D3 = 20
ELSE
D3 = 30
ENDIF

IF (L1.EQ.10) THEN 
D3 = 10 
ELSEIF (L1.EQ.20) THEN 
D3 = 20 
ELSE
D3 = 30
ENDIF 

Logical operators:
  • Comparison

    .EQ.

    eq ual (equal)

    .GT.

    g reater t hen (greater than)

    .GE.

    g reater e qual (greater than or equal to)

    .LT.

    l ower t hen (less than)

    .LE.

    l ower e qual (less than or equal to)

  • Linking

    .AND.

    (both conditions - right and left of .AND. - must be fulfilled)

    .OR.

    (one of the two conditions - to the right or left of .OR. - must be fulfilled)

    .NE.

    n ot e qual (unequal)

  • Boolean values

    .TRUE.

    An expression can be equal to "true".

    --- .EQ..TRUE. ---

    .FALSE.

    An expression can be equal to "false".

    --- .EQ..FALSE. ---

Operator for linking strings

The // operator makes it possible to link variable values with a text (or other variable values).

[Note]Note

Variables must be declared without $.

Examples:

TYPE=‘new‘//TYPE

CONC = ABC//'0'//PQR//XYZ

In PARTdesigner the use of variables within a string works:

Examples:

C= 'Test --- $A.-$B.'

NENN = '$H.x$B.x$L.'

This does NOT work with ERP mapping, so the use of the // operator is particularly helpful here.

Basic arithmetic operations

+, -, *, /

Basic arithmetic operations

**

Potentiation

Mathematical functions

Number = ABS (number)

Absolute value:

Example:

|-3.4| = 3.4

Number = INT (number)

Number = AINT (number)

INT converts the number into an integer.

AINT truncates the decimal places.

The result of INT is the same as with AINT, as long as the number is in the range of integers, i.e. -2^31 to 2^31.

Convert to "Integer" / Truncate decimal places

Example:

AINT(3.1) = 3
AINT(3.9) = 3
AINT(-3.9) = -3

Number = ANINT (number)

Number = NINT (number)

The two functions are identical.

Next real integer (rounding)

Example:

ANINT(3.1) = 3
ANINT(3.9) = 4
ANINT(4.5) = 5
ANINT(-3.9) = -4

Number = DIM (number,number)

Positive difference:

As long as the first number is bigger than the second, the calculation is: number 1 - number 2; otherwise the result is 0.

Example:

DIM(8,4) = 4
DIM(4,8) = 0

Number = SQRT (number)

Square root

Number = EXP (number)

Exponential function

Number = LOG (number)

Natural logarithm

Number = LOG10 (number)

Logarithm to base 10

Number = MAX (...)

MAX (A1, A2, A3,…) 

Maximum value of parameters

Number = MIN (...)

MAX (A1, A2, A3,…) 

Minimum value of parameters

Number = MOD (number,number)

Remainder calculation:

A - INT (A/P)*P

Example

MOD(11,4) = 3

11 - (INT(11/4)*4) = 11 - 2*4 = 3

11 / 4 == 2 Rest 3

Number = SIGN (number,number)

Sign transfer: |A| signum (B)

SIGN(A,B) means that the return value is the value of A with the sign of B.

Example:

SIGN(10,1)   =  10
SIGN(10,-1)  = -10

SIGN(-10,1)  =  10
SIGN(-10,-1) = -10

Angle functions

Number = SIN (number)

Sine

Number = SINH (number)

Hyperbolic sine

Number = COS (number)

Cosine

Number = COSH (number)

Hyperbolic cosine

Number = TAN(number)

Tangent

Number = TANH(number)

Cosine tangent

Inverse functions to above mentioned:

Number = ASIN (number)

Arc sine

Number = ACOS (number)

Arc cosine

Number = ATAN (number)

Arc tangent

Number = ATAN2 (number,number)

Arc tangent with two arguments

ATAN2 is an enhancement to ATAN and like that an inverse function of the angular function Tangent.

It takes two real numbers as argument, in contrary to the normal Arc Tangent, which only takes one number. In this way it has enough information to be able to return values in the full range of 360 degrees (meaning four quadrants) and is not restricted to two quadrants (as the normal Arc Tangent).

atan2(y,x) returns the angle θ between the ray to the point (x,y) and the positive x-axis, confined to (-Pi,Pi].

The result is returned in degrees.

[Note]Note

At angular functions the entry in brackets mirrors the degree value.

Text-related functions:

Number = ATOF ('text')

Changes text to number:

Example:

ATOF ('3.2') -> 3.2

LEN ('text')

LEN (variable)

Length of text:

LEN('abcd')  = 4
LEN(VAR)  = Länge des Textes in der Variable VAR
text = SUBSTR (text,number,number)

Section from text

The first parameter is the text, the second indicates at which symbol the extract begins, and the third parameter indicates the length of the extract.

Example:

SUBSTR('Hallo Welt',1,5) -> Hallo
SUBSTR('Hallo Welt',7,4) -> Welt

[Note]Note

The following functions cannot be used: FORMATSTR, FORMATVAL, KFIX

Thread functions

text = GETTHREADTEXT (number,text,text,number)

Used with threads:

Using the following expression you can generate different output.

Example:

NAME  =  GETTHREADTEXT(D,'DIN 13','',P,'NAME')

A detailed description can be found under Section 7.9.3.14.1.1.2, “Various thread pitches and derived automatic calculations for e.g. line description and core diameter.

Number = GETTHREADVALUE (number,text,text,number)

Compare the preceding function

GETTHREADTEXT gets a text from the table and GETTHREADVALUE a DOUBLE value.

Translation functions

text = TRANSLATE ('text')

TRANSLATE translates a text into the current language.

Also see Section 7.8.12.7, “ Translation functions” -> Example 1

text = TRANSLATE (VARIABLENNAME)

However, if you want to use the visible, translated value in the line description [Row label], data sheet [Data sheet], 2D derivation, etc., you can use the "TRANSLATE(VARIABLENNAME)" function.

Also see Section 7.8.12.7, “ Translation functions” -> Example 2 and 3

text = $VARIABLENNAME(SRC=VALDESC).

Also see Section 7.8.12.7, “ Translation functions” -> Example 4