fpclassify - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# fpclassify

From cppreference.com
< c‎ | numeric‎ | math

Defined in header `<math.h>` |  |
#define fpclassify(arg) /* implementation defined */ |  | (since C99)

Categorizes floating point value `arg` into the following categories: zero, subnormal, normal, infinite, NAN, or implementation-defined category. The macro returns an integral value.

### [edit] Parameters

arg | - | floating point value

### [edit] Return value

One of FP_INFINITE, FP_NAN, FP_NORMAL, FP_SUBNORMAL, FP_ZERO or implementation-defined type, specifying the category of `arg`.

### [edit] Example

Run this code

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

    int main(void)
    {
        printf("FP_NAN       = %d\n", FP_NAN);         // 0
        printf("FP_INFINITE  = %d\n", FP_INFINITE);    // 1
        printf("FP_ZERO      = %d\n", FP_ZERO);        // 2
        printf("FP_SUBNORMAL = %d\n", FP_SUBNORMAL);   // 3
        printf("FP_NORMAL    = %d\n", FP_NORMAL);      // 4
        printf("\n");

        printf("fpclassify(NAN)         = %d\n", fpclassify(NAN));           // 0
        printf("fpclassify(INFINITY)    = %d\n", fpclassify(INFINITY));      // 1
        printf("fpclassify(0.0)         = %d\n", fpclassify(0.0));           // 2
        printf("fpclassify(DBL_MIN/2.0) = %d\n", fpclassify(DBL_MIN/2.0));   // 3
        printf("fpclassify(1.0)         = %d\n", fpclassify(1.0));           // 4

        return 0;
    }

Possible output:

    FP_NAN       = 0
    FP_INFINITE  = 1
    FP_ZERO      = 2
    FP_SUBNORMAL = 3
    FP_NORMAL    = 4

    fpclassify(NAN)         = 0
    fpclassify(INFINITY)    = 1
    fpclassify(0.0)         = 2
    fpclassify(DBL_MIN/2.0) = 3
    fpclassify(1.0)         = 4

### [edit] See also

isfinite (C99) | checks if the given number has finite value (function) [edit]
isinf (C99) | checks if the given number is infinite (function) [edit]
isnan (C99) | checks if the given number is NaN (function) [edit]
isnormal (C99) | checks if the given number is normal (function) [edit]
C++ documentation for fpclassify

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/numeric/math/fpclassify&oldid=70146"