In automation, INT and REAL are still common default types. That made sense when PLCs
had limited memory and slower CPUs.
Modern PLCs are different. Many systems now run on 32-bit or 64-bit CPUs with enough memory
that the old defaults deserve another look. In many applications, DINT and LREAL are
better internal types.
Floating Point
The difference between LREAL and REAL matters in scaling, filtering, integration, and
coordinate transformations.
A 32-bit REAL has 24 bits of significand precision, including the implicit leading bit.
Around \(1.0\), the distance to the next representable value is \(2^{-23}\). This distance
is one ULP1.
A 64-bit LREAL has 53 bits of significand precision. Around \(1.0\), one ULP is
\(2^{-52}\). That gives LREAL \(2^{29}\) times finer spacing around \(1.0\) than
REAL.
Before addition or subtraction, floating-point values are aligned to the same exponent. A normalized binary value like \(100.0_2\) is represented as \(1.0_2 \times 2^2\). If the operands have very different magnitudes, the smaller operand may no longer affect the stored result after rounding.
For example, with a 32-bit REAL and the usual round-to-nearest mode:
The value \(2^{-24}\) is half an ULP at \(1.0\). It is too small to change the stored
REAL value. With LREAL, the same addition is still far above the rounding limit.
Subtraction has a different problem. If two operands are almost equal, the leading digits cancel. The result may be mathematically correct, but it can contain few meaningful bits. This is called cancellation.
A transformation like
\[ \begin{align*} \frac{a}{b-c} \end{align*} \]can become numerically fragile when \(b-c\) is close to zero. LREAL does not fix a bad
formula, but it gives more precision before rounding becomes visible.
The exact intermediate precision depends on the CPU, compiler, and runtime. The important
point is simpler: once a value is stored as REAL, it is rounded to 32-bit precision. If
the application performs physical scaling or intermediate calculations, LREAL is usually
the safer internal type.
Integer
The argument for DINT is less about numerical precision and more about practical range.
In IEC 61131-3, INT is commonly a signed 16-bit integer. That gives a range from
\(-32768\) to \(32767\). This is enough for many field values, but it is small for
counters, indexes, intermediate calculations, scaled values, and accumulated totals.
DINT is a signed 32-bit integer. It can represent signed and unsigned 16-bit field values
without changing the internal type. It also covers common 24-bit ADC values without forcing
a redesign of the calculation chain.
This does not mean every variable should be a DINT. Hardware mappings, protocol data,
and packed structures should use the exact type required by the interface. But inside the
application logic, DINT is often the more robust default.
Conclusion
INT and REAL are still valid types, but they should not be automatic defaults in modern
PLC projects.
Use DINT when a value is a general-purpose integer. It avoids tight 16-bit limits and
gives enough range for most counters, indexes, and intermediate calculations.
Use LREAL when a value represents a physical quantity, a scaling result, or an
intermediate calculation. The extra precision is cheap on modern hardware and can
prevent avoidable rounding errors.
Keep narrow types at the system boundary. Use the type required by the fieldbus, hardware register, protocol, or memory layout. Then convert to a more robust internal type for the application logic.
The practical rule is simple:
Use exact types at the boundary. Use robust types inside the application.
Unit in the Last Place ↩︎
