isNaN(Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

3.10 / 1.00.00


This function checks if the provided value is not a number. Infinity is considered a number.

This should be used to verify results of calculations where it is possible to have an illegal value.

Besides the functions that return NaN on invalid input, it is also possible to get NaN by using normal operators e.g. 0/0, or other cases where the result is undefined.

 

Note: This function works with DOUBLE, but can also work with FLOAT as described in the Floating-point math introductory section.

 

Input:

V : DOUBLE

Value to check.

 

Returns: BOOL

True if the value is not a number, False otherwise.

 

Declaration:

FUNCTION isNaN : BOOL;
VAR_INPUT
v : DOUBLE;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
INCLUDE math.inc
 
PROGRAM test;
VAR
  a : DOUBLE;
END_VAR;
 
a := asin(v := 1.2);
IF isNaN(v := a) THEN
  DebugMsg(message := "Invalid value");
END_IF;
 
END_PROGRAM;