BOOL, INT, DINT, REAL: choosing the right type
Picking a type is a decision about range, memory and precision, and getting it wrong shows up as an overflow nobody sees.
By the LADX engineering team
Short answer
The four that cover most work are BOOL for a single bit, INT for whole numbers from -32,768 to 32,767, DINT for a 32-bit integer up to about 2.1 billion, and REAL for a 32-bit floating point value. The common failure is INT overflow, which wraps silently to a negative number with no error and no warning.
Four types cover most industrial work, and the choice between them is about range, memory and precision.
The four
- BOOL: one bit. On or off.
- INT: 16 bits, -32,768 to 32,767.
- DINT: 32 bits, roughly plus or minus 2.1 billion.
- REAL: 32 bits of floating point, about seven significant digits.
The failure that costs the most
INT overflow. Multiply 1,000 by 100 in INTs and the answer is not 100,000; it is a negative number, arrived at silently.
This bites in scaling code, in totalisers, and in anything counting parts over a shift. The fix is to use a DINT for the destination and for the intermediate, not only the final result.
If a value can grow over time, it is a DINT. Shift totals, motor hours, part counts.
REAL is not a safe default
Floating point cannot represent 0.1 exactly. Two REALs that should be equal frequently are not, which makes equality comparisons unreliable, and repeated addition accumulates error.
Use REAL where you are representing a measured physical quantity. Use integers where you are counting.
Sources and further reading
- Rockwell Logix 5000 I/O and Tag Data manualliterature.rockwellautomation.com
- Single-precision floating point (REAL) explained (Wikipedia)en.wikipedia.org
Common questions
- What happens when an INT overflows in a PLC?
- It wraps. Adding one to 32,767 gives -32,768, silently, with no fault and no indication. Any calculation whose intermediate result can exceed 32,767 needs a DINT for the destination, and often for the intermediate as well.
- Should I use REAL for everything to be safe?
- No. REAL cannot represent most decimal values exactly, so equality comparisons are unreliable and repeated arithmetic accumulates error. Use integers for counting and REAL for measured quantities and calculations that genuinely need fractions.
Keep reading
- Fundamentals
How a virtual PLC works: inside one scan
The mechanism of a software PLC, from the input image to the watchdog: the scan clock, catch-up in a throttled browser tab, tasks, RETAIN, warm and cold restart, and fault codes, with the real numbers from the LADV runtime.
- Fundamentals
PLC tasks and the watchdog: cyclic, event and continuous, and what a fault does
How PLC tasks start (cyclic, event, continuous), how one CPU shares its time between them, and what a watchdog fault is, with a two-task program and the LADV behaviour as a worked example.
- Fundamentals
How to force a PLC input or output, and how force differs from modify
What forcing does in the I/O image, how it differs from a one-off modify, why forces persist, the safety discipline around them, and how to practise on a virtual PLC.