Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
10
Добавлен:
11.10.2020
Размер:
3.39 Mб
Скачать

The IEC Operators

311

Numeric Functions

 

 

 

When you perform a type conversion from a larger to a smaller type, you risk losing some information.

Examples in ST:

i:=TRUNC(1.9); (* Result is 1 *)

i:=TRUNC(-1.4); (* result is -1 *).

Example in IL:

LD 2.7

TRUNC

GE %MW8

12.10Numeric Functions

12.10.1ABS

Returns the absolute value of a number. ABS(-2) equals 2.

The following type combinations for input and output variables are possible:

IN

 

OUT

INT

 

INT, REAL, WORD, DWORD, DINT

 

 

 

REAL

 

REAL

 

 

 

BYTE

 

INT, REAL, BYTE, WORD, DWORD, DINT

 

 

 

WORD

 

INT, REAL, WORD, DWORD, DINT

 

 

 

DWORD

 

REAL, DWORD, DINT

 

 

 

SINT

 

REAL

 

 

 

USINT

 

REAL

 

 

 

UINT

 

INT, REAL, WORD, DWORD, DINT, UDINT, UINT

 

 

 

DINT

 

REAL, DWORD, DINT

 

 

 

UDINT

 

REAL, DWORD, DINT, UDINT

 

 

Example in IL:

 

LD

2

 

ABS

 

 

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

312 The IEC Operators

Numeric Functions

ST

i

(*Result is 2 *)

Example in ST:

i:=ABS(-2);

Example in FBD:

12.10.2SQRT

Returns the square root of a number.

IN can be type BYTE, WORD, DWORD, INT, DINT, REAL, SINT, USINT, UINT, UDINT, OUT must be type REAL.

Example in IL:

LD 16

SQRT

ST

q

(*Result is 4 *)

Example in ST:

q:=SQRT(16);

Example in FBD:

12.10.3LN

Returns the natural logarithm of a number.

IN can be type BYTE, WORD, DWORD, INT, DINT, REAL, SINT, USINT, UINT, UDINT, OUT must be type REAL.

Example in IL:

LD 45

LN

ST

q

(*Result is 3.80666 *)

Example in ST:

q:=LN(45);

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

The IEC Operators

313

Numeric Functions

 

 

 

Example in FBD:

12.10.4LOG

Returns the logarithm of a number in base 10.

IN can be type BYTE, WORD, DWORD, INT, DINT, REAL, SINT, USINT, UINT, UDINT, OUT must be type REAL.

Example in IL:

LD 314.5

LOG

ST

q

(*Result is 2.49762 *)

Example in ST:

q:=LOG(314.5);

Example in FBD:

12.10.5EXP

Returns the exponential function.

IN can be type BYTE, WORD, DWORD, INT, DINT, REAL, SINT, USINT, UINT, UDINT, OUT must be type REAL.

Example in IL:

LD 2

EXP

ST

q

(* result is 7.389056099 *)

Example in ST:

q:=EXP(2);

Example in FBD:

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

314 The IEC Operators

Numeric Functions

12.10.6SIN

Returns the sine of a number.

IN can be type BYTE, WORD, DWORD, INT, DINT, REAL, SINT, USINT, UINT, UDINT, OUT must be type REAL.

Example in IL:

LD 0.5

SIN

ST

q

(*Result is 0.479426 *)

Example in ST:

q:=SIN(0.5);

Example in FBD:

12.10.7COS

Returns the cosine of number. The value is calculated in arch minutes.

IN can be type BYTE, WORD, DWORD, INT, DINT, REAL, SINT, USINT, UINT, UDINT, OUT must be type Typ REAL.

Example in IL:

LD 0.5

COS

ST

q

(*Result is 0.877583 *)

Example in ST:

q:=COS(0.5);

Example in FBD:

12.10.8TAN

Returns the tangent of a number. The value is calculated in arch minutes. IN can be type BYTE, WORD, DWORD, INT, DINT, REAL, SINT, USINT, UINT, UDINT, OUT must be type REAL.

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32