Arithmetic operations, higher range of values

Question:

How can the range of values applied to arithmetic calculations be extended?

Answer:

If the range of values, which is applied by the PLC to arithmetic calculations, is to be extended, a type conversion of the variables to the next higher data type at the inputs of the operation must be executed. For this purpose the corresponding conversion functions must be applied.

This is especially interesting, if the formula includes multiplication and division at the same time. If the multiplication is effected first, there is a danger that its result is not within the range of values, If, however, the division is executed first, its result could be useless because of rounding. Remedial measure: Extension of the range of values by type conversion.

Example:
nIn : INT;
nOut : INT;

nOut := nIn * 10000/3333;
with nIn > 3 the range of values of INT is exceeded during multiplication -> data type overflow

Remedial measure:
nOut := DINT_TO_INT( INT_TO_DINT( nIn ) * 10000 / 3333 )
Due to the type conversion the calculation is effected in the range of values of DINT.

URL for linking this AKB article: https://www.lenze.com/en-de/go/akb/20010151/1/
Kontaktformular