RealIsNaN
This function tests whether a value is NaN (Not a Number). If the return value is TRUE, the value is NaN.
FUNCTION RealIsNaN : BOOL
VAR_INPUT
x : REFERENCE TO REAL;
END_VAR
The following points rank among the main features of NaN values:
- All arithmetic operations that use NaN as input data return NaN as the result.
- All relational operators =, !=, > < >= <= always return the value False if at least one of the operands is NaN.
- The standard C functions
isnan()
or_isnan()
or the PLC functions LrealIsNaN() and RealIsNaN (Tc2_Utilities library) return the value True if the argument has the value NaN. - The expression
isnan(a)
is equivalent to the expression!(a == a)
orNOT(a = a)
.
The fact that NaN values reproduce themselves when used in further calculations is advantageous in that invalid values cannot be overlooked.
CAUTION | |
Software malfunctions NaN values may only be used in PLC libraries, in particular as control values in functions for Motion Control and for drive control, if they are expressly approved! Otherwise NaN values can lead to potentially dangerous malfunctions of the software concerned! |
CAUTION | |
Floating point exceptions If NaNs are to be used and processed in the application, the FP exceptions must be switched off. Otherwise, comparisons with NaN can lead to an exception, which will cause a stop of the runtime and possible machine damage. |
Requirements
Development environment | Target platform | PLC libraries to be integrated (category group) |
---|---|---|
TwinCAT v3.1.4024.32 | PC or CX (x86, x64, ARM) | Tc2_Utilities (System) >= 3.3.50.0 |