fpclassify - C math.h

C examples for math.h:fpclassify

type

macro/function

From

<cmath>
<ctgmath>
<math.h>

Description

Returns a value of type int that matches one of the classification macro constants, depending on the value of x:

value description
FP_INFINITE Positive or negative infinity (overflow)
FP_NAN Not-A-Number
FP_ZERO Value of zero
FP_SUBNORMAL Sub-normal value (underflow)
FP_NORMAL Normal value (none of the above)

Prototype

int fpclassify (float x); //function
int fpclassify (double x);//function
int fpclassify (long double x);//function
    fpclassify(x)//macro

Parameters

Parameter Description
x The value to classify.

Return value

One of the following int values:

  • FP_INFINITE,
  • FP_NAN,
  • FP_ZERO,
  • FP_SUBNORMAL or
  • FP_NORMAL.

Example

Demo Code


#include <stdio.h>
#include <math.h>

int main()/*  w w  w .j  a v  a2s .c  o m*/
{
  int a = 0;

  double d = 1.0 / a;
  switch (fpclassify(d)) {
    case FP_INFINITE:  printf ("infinite");  break;
    case FP_NAN:       printf ("NaN");       break;
    case FP_ZERO:      printf ("zero");      break;
    case FP_SUBNORMAL: printf ("subnormal"); break;
    case FP_NORMAL:    printf ("normal");    break;
  }
  return 0;
}

Related Tutorials