CheckDivReal : REAL

CheckDivReal : REAL 1:

If you define functions in your project with the name CheckDivReal, you can use them to check the value of the divisor if you use the operator DIV, for example to avoid a division by 0. The name of the function is defined and may have only this identifier.

CheckDivReal : REAL 2:

The function can cause a significant increase in system load, so it should only be used for testing purposes.

VAR_INPUT
    divisor : REAL;
END_VAR

Example of CheckDivReal implementation:

IF divisor = 0 THEN
    CheckDivReal := 1;
ELSE
    CheckDivReal := divisor;
END_IF

Operator DIV uses the output of function CheckDivReal as divisor. In a program like shown in the following example this avoids a division by 0, the divisor (d) is set from 0 to 1. So the result of the division is 799.

CheckDivReal : REAL 3: