Skip to main content
Knowledgebase
Home
Renesas Singapore - Knowledgebase

"Is floating-point variable is a or not-a-number in C source code? "

Latest Updated:02/27/2015

Question:

Is there any way to check whether a floating-point variable is or is not a not-a-number in C source code?

Answer:

It is possible to check whether a floating-point-type variable is or is not a not-a-number by comparing the variable to itself.

   ----------------------------
   float arg;

   if(arg==arg) {
       /*Not a not-a-number*/
   }
   else {
       /*Not-a-number*/
   };
   ----------------------------
Suitable Products
C Compiler Package for RH850 Family
C/C++ Compiler Package for RX Family