How does Siemens PLC support floating-point and square root operations?

2026-09-08

1. What Floating-Point Data Types Are Supported by Siemens PLCs?

Siemens PLCs support three floating-point data types: REAL (32-bit, IEEE 754 single precision), LREAL (64-bit, IEEE 754 double precision), and S5TIME (a special format for timer values, but not a true floating-point type for mathematical operations). The REAL type is the most commonly used floating-point format in Siemens PLC programming. It provides a range of approximately ±1.18×10⁻³⁸ to ±3.40×10³⁸ with a precision of about 7 decimal digits. The LREAL type is available on S7-1500 and S7-400 CPUs with firmware version 2.0 or higher, providing approximately 15 decimal digits of precision. 

Siemens 6AU1410-2AA00-0AA0

The table below compares the characteristics of these data types across Siemens PLC families.

Data type Bit length Precision (decimal digits) Supported CPU families Instruction set availability
REAL 32 6 – 7 S7-300, S7-400, S7-1200, S7-1500 Full math instruction set
LREAL 64 15 – 16 S7-400 (firmware 2.0+), S7-1500 Limited to newer CPUs
S7_TIME 32 N/A (integer format) All Siemens PLCs Not applicable for math


When programming a Siemens PLC, you must select the appropriate data type for your application. For most process control applications, REAL is sufficient. For applications that require high precision, such as coordinate calculation for CNC or precision metering, you may need LREAL. In our factory, we use REAL for most applications and LREAL only when the cumulative error of multiple REAL operations exceeds the tolerance. Yueyang Tongtu E-commerce Co., Ltd. supplies Siemens PLC units with both REAL and LREAL support, and we provide guidance on selecting the right CPU based on your precision requirements.


2. Which Instructions Are Used for Floating-Point and Square Root Operations?

Siemens PLCs provide a comprehensive set of floating-point instructions in both LAD (ladder diagram) and STL (statement list) programming languages. The core instructions include: ADD (addition), SUB (subtraction), MUL (multiplication), DIV (division), and SQRT (square root). The instructions operate on REAL and LREAL data types. The table below lists the instructions, their syntax, and the CPU cycle time for each operation.

Operation LAD instruction STL instruction Execution time (S7-1500) Execution time (S7-1200)
Addition (REAL) ADD +R ~0.05 µs ~0.15 µs
Subtraction (REAL) SUB -R ~0.05 µs ~0.15 µs
Multiplication (REAL) MUL *R ~0.05 µs ~0.15 µs
Division (REAL) DIV /R ~0.08 µs ~0.20 µs
Square root (REAL) SQRT SQRT ~0.12 µs ~0.35 µs
Square root (LREAL) SQRT (with LREAL tag) SQRT ~0.25 µs Not supported

The SQRT instruction expects the input value to be a non-negative REAL or LREAL number. If a negative value is provided, the instruction will return an undefined result (typically a NaN or a negative number, depending on the CPU firmware). In our factory, we always check the input value before calling SQRT to ensure it is non-negative. We also handle the case where the input is zero, which returns zero.


3. What Are the Precision Considerations When Using Floating-Point Operations?

Floating-point operations in Siemens PLCs follow the IEEE 754 standard. This means that not all numbers can be represented exactly, and the result of a sequence of operations may accumulate rounding errors. For example, the number 0.1 cannot be represented exactly in binary floating-point. When you add 0.1 ten times, the result may be 0.99999999 instead of 1.0. This is not a bug; it is a fundamental limitation of floating-point representation. To manage this, you should round the result to the required precision using the ROUND or TRUNC instructions. In our factory, we recommend using a tolerance of 1e-6 when comparing floating-point values in Siemens PLC programs.

Example of handling precision in STL:
L 0.1
T #temp_real
L #temp_real
L 0.1
+R
T #temp_real
... (repeat) ...
L #temp_real
L 1.0
-R
L 1e-6
>R
JC #outside_tolerance

The square root operation is also subject to precision limitations. The SQRT instruction uses an iterative algorithm that provides a result accurate to the last bit of the mantissa. For most applications, this is sufficient. For high precision applications, such as flow measurement with differential pressure transmitters, we recommend using the SQRT instruction with REAL data and then converting the result to a scaled integer value for display.


4. How Does the CPU Family Affect Floating-Point Performance?

The performance of floating-point operations varies significantly between Siemens PLC families. The S7-1500 family has a dedicated floating-point unit (FPU) that executes floating-point instructions in hardware. The S7-1200 family also has hardware floating-point support, but the execution time is slightly longer. The S7-300 family (especially older models) executes floating-point instructions in software, which can take 10 to 20 times longer. The S7-400 family has a high-performance FPU and supports both REAL and LREAL operations. When selecting a Siemens PLC for an application that requires extensive floating-point calculations, the choice of CPU is critical. In our factory, we recommend the S7-1500 for applications that involve more than 100 floating-point operations per scan cycle.


Frequently Asked Questions About Siemens PLC Math Operations

Question 1: Why does my Siemens PLC SQRT instruction return an error when the input is a negative number?
Answer: The SQRT instruction is mathematically defined only for non-negative numbers. If you provide a negative input, the result is undefined. Depending on the CPU firmware, the result may be a NaN (Not a Number), a very large negative number, or the CPU may set the EN0 bit to false. In the S7-1500 family, the SQRT instruction sets the OV (overflow) bit and the OS (stored overflow) bit when the input is negative. To avoid this error, you should check the input value before calling SQRT. In our factory, we use a comparison instruction to check if the input is less than zero and set the result to zero (or another safe value) in that case.
Question 2: What is the difference between the SQRT and the NORM_X instruction for square root calculations?
Answer: The SQRT instruction calculates the square root of a single floating-point number. The NORM_X instruction is used for scaling and normalization, not for calculating square roots. NORM_X scales a value to a percentage or a different range, but it does not perform a square root calculation. If you need to calculate the square root of a differential pressure signal to obtain flow, you use the SQRT instruction. If you then need to scale the flow value to a 0-100 percent range, you use the NORM_X instruction. In our factory, we often use SQRT followed by NORM_X in a flow measurement application. The SQRT operation is the mathematical function; NORM_X is the scaling function.
Question 3: Can I use floating-point operations in interrupt routines on a Siemens PLC?
Answer: Yes, you can use floating-point operations in interrupt routines, but you need to be aware of the execution time. Interrupt routines must be short to avoid delaying the main scan cycle. In the S7-1200 and S7-1500 families, floating-point operations execute quickly (less than 1 microsecond for most operations), so using them in an interrupt routine is acceptable as long as the total interrupt routine execution time is below the interrupt period. In the S7-300 family, floating-point operations can take 5 to 20 microseconds, which may be too long for a high-frequency interrupt. In our factory, we recommend testing the interrupt routine execution time using the CPU's runtime meter before deploying the code. Yueyang Tongtu E-commerce Co., Ltd. provides Siemens PLC units with detailed technical documentation that includes instruction execution times.

Summary for Automation Engineers

Siemens PLCs provide comprehensive support for floating-point and square root operations through the REAL and LREAL data types and a complete set of math instructions. The performance and precision depend on the CPU family, the data type, and the programming language used. The S7-1500 family offers the best performance with hardware floating-point support and sub-microsecond execution times. For most applications, the REAL data type provides sufficient precision. For high precision applications, the LREAL data type is available on the S7-1500 and S7-400. The key to successful programming is to select the correct data type, check for invalid inputs (especially for SQRT), and manage rounding errors by using a tolerance value.

Yueyang Tongtu E-commerce Co., Ltd. supplies Siemens PLC units with full technical support. We provide programming guidance and troubleshooting assistance for all Siemens PLC models. Our technical team can help you optimize your floating-point calculations for performance and precision.

Previous:No News
Next:No News

Leave Your Message

  • Click Refresh verification code