Namespaces
Variants
Views
Actions

std::fpclassify

From cppreference.com
< cpp‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Exponential functions
(C++11)
(C++11)
(C++11)
(C++11)
Power functions
(C++11)
(C++11)
Trigonometric and hyperbolic functions
(C++11)
(C++11)
(C++11)
Error and gamma functions
(C++11)
(C++11)
(C++11)
(C++11)
Nearest integer floating point operations
(C++11)(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Floating point manipulation functions
(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)
(C++11)
Classification/Comparison
fpclassify
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Macro constants
(C++11)(C++11)(C++11)(C++11)(C++11)
 
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.

Contents

[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

#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

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