Rules / real-to-word-mul
REAL_TO_WORD(x) * N: can the WORD overflow
A WORD holds 0..65535. If the product is larger, the high bits are lost and the register receives a wrapped value. The rule flags such places so the range can be checked.
Severity: Warning
Rule id: real-to-word-mul
REAL_TO_WORD(...)*N may overflow WORD
What the rule checks
WORD is limited to 0..65535, so make sure the product does not overflow.
What it does to the plant
An exchange register for SCADA or the HMI gets a small number instead of a large one: flow or energy on screen suddenly drops to near zero.
Example
PROGRAM ExchangeVAR rFlow : REAL; wFlowReg : WORD;END_VARwFlowReg := REAL_TO_WORD(rFlow) * 100;
PROGRAM ExchangeVAR rFlow : REAL; dwFlowReg : DWORD;END_VARdwFlowReg := REAL_TO_DWORD(rFlow * 100.0);
Both listings are run through the linter by an automated test: the rule fires on the first and stays silent on the second.
How to fix
- Check the range; if the product can exceed 65535, use DWORD or UDINT.
Upload a PLCopen XML or CODESYS .export file: the report is free and the code is not stored.
The same linter without uploading a file: command line and GitHub Action.
Related rules
2026-11-26