Which products are affected?
ESP-DDS2-x (Drive PLC Developer Studio V2.x)
What happens?
There are two different kinds of constants:
- Number constant: a numerical value in the PLC logic (source code)
- Variable constant (Typed Literal): a variable declared as constant between the keywords VAR CONSTANT and END_VAR
Dependent on the value of the constant the division of two integer constants leads to an incorrectly calculated result.
Example:
udnVar:=3000000000/10; (*Result of the division = 4165470567*)
When does the problem occur?
- If an integer number constant has a value larger than or equal to 2^31 (≥ 2147483647) in the numerator of the division the result of the division is wrong.
- If an integer variable constant has a value larger than or equal to 2^31 (≥ 2147483647) in the numerator of the division and if the Replace constants option is activated in the Compilation options category of the Options dialog (menu item: Project>Options) the result of the division is wrong.
Possible diagnostics?
When variable constants are used check whether the
Replace constants option is activated (see above).
Short-term measures/recommendations?
- In the PLC logic the constant in the numerator of the division is to be replaced by a variable (declaration between the keywords VAR and END_VAR) of the UDINT or DWORD data type which has been initialised with the value of the constant.
- Or, even better:
- In the PLC logic the division is to be replaced by a constant whose value corresponds to the calculated result of the division.
Evaluation:
The division of very large integer constants (≥ 2147483647) leads to a faulty result. This function restriction is detected during commissioning at the latest. Expressions in which constants have been divided as described before are rather seldom in practice.