##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::fpclassify

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

Defined in header `<cmath>` |  |
int fpclassify( float arg ); |  | (since C++11)
int fpclassify( double arg ); |  | (since C++11)
int fpclassify( long double arg ); |  | (since C++11)

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

### [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 <iostream>
    #include <cmath>
    #include <cfloat>

    int main() {
        std::cout<<"FP_NAN       = "<<FP_NAN      <<'\n';// 0
        std::cout<<"FP_INFINITE  = "<<FP_INFINITE <<'\n';// 1
        std::cout<<"FP_ZERO      = "<<FP_ZERO     <<'\n';// 2
        std::cout<<"FP_SUBNORMAL = "<<FP_SUBNORMAL<<'\n';// 3
        std::cout<<"FP_NORMAL    = "<<FP_NORMAL   <<'\n';// 4
        std::cout<<'\n';
        std::cout<<"std::fpclassify(NAN)         = "<<std::fpclassify(NAN)        <<'\n';
        std::cout<<"std::fpclassify(INFINITY)    = "<<std::fpclassify(INFINITY)   <<'\n';
        std::cout<<"std::fpclassify(0.f)         = "<<std::fpclassify(0.f)        <<'\n';
        std::cout<<"std::fpclassify(FLT_MIN/2.f) = "<<std::fpclassify(FLT_MIN/2.f)<<'\n';
        std::cout<<"std::fpclassify(1.f)         = "<<std::fpclassify(1.f)        <<'\n';

        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.f)         = 2
    fpclassify(FLT_MIN/2.f) = 3
    fpclassify(1.f)         = 4

### [edit] See also

isfinite (C++11) | checks if the given number has finite value (function) [edit]
isinf (C++11) | checks if the given number is infinite (function) [edit]
isnan (C++11) | checks if the given number is NaN (function) [edit]
isnormal (C++11) | checks if the given number is normal (function) [edit]
numeric_limits | provides an interface to query properties of all fundamental numeric types. (class template) [edit]
C documentation for fpclassify

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