C Data Type Functions - C isnormal






Prototype C99

The C99 prototype is listed as follows.

macro isnormal(x) 

Prototype C++11

The C++11 prototype is listed as follows.

bool isnormal (float x);
bool isnormal (double x);
bool isnormal (long double x); 
         

Returns whether x is a normal value: i.e., whether it is neither infinity, NaN, zero or subnormal.

Parameter

This function has the following parameter.

x
A floating-point value.

Return

A non-zero value ( true) if x is normal; and zero ( false) otherwise.

Example


#include <stdio.h> /* printf */
#include <math.h> /* isnormal */
//from  ww w  . j  av a2  s .co  m
int main()
{
  printf ("isnormal(1.0) : %d\n",isnormal(1.0));
  printf ("isnormal(0.0) : %d\n",isnormal(0.0));
  return 0;
} 

       

The code above generates the following result.





Example 2


#include <stdio.h>
#include <math.h>
#include <float.h>
 /*from w  w  w.  j a v  a2s  .c  o m*/
int main(void)
{
    printf("isnormal(NAN)         = %d\n", isnormal(NAN));
    printf("isnormal(INFINITY)    = %d\n", isnormal(INFINITY));
    printf("isnormal(0.0)         = %d\n", isnormal(0.0));
    printf("isnormal(DBL_MIN/2.0) = %d\n", isnormal(DBL_MIN/2.0));
    printf("isnormal(1.0)         = %d\n", isnormal(1.0));
}

The code above generates the following result.