The fpclassify() function are defined in header math.h header in C and cmath library in C++. This function is used to get the value of type int that matches one of the classification macro constants (depending on the value of x).
Syntax:
int fpclassify(int x); int fpclassify(float x); int fpclassify(double x); int fpclassify(long double x);
Parameters: This method accepts a parameter x which is the value to be matched with one of the macro constants of this method. It can be integer, float, double or long double.
Return Value: This function returns integer values for the macro constants as follows:
- FP_INFINITE: When the specified value is Positive or negative infinity
- FP_NAN: When the specified value is not a Number
- FP_ZERO: When the specified value is a zero.
- FP_SUBNORMAL: When the specified value is a positive or negative denormalized value
- FP_NORMAL: When the specified value is a positive or negative normalized non-zero value
Below example demonstrate the use of fpclassify() method:
// C++ program to demonstrate // the use of fpclassify() method #include <iostream> #include <math.h> using namespace std; // Function to implement fpclassify() method void fpclassification(double x) { // fpclassify() method switch (fpclassify(x)) { // For the data to be infinite case FP_INFINITE: cout << "Infinite Number \n"; break; // For the data to be not defined // as in divide by zero case FP_NAN: cout << "Not a Number \n"; break; // For the data to be zero case FP_ZERO: cout << "Zero \n"; break; // For the data to be subnormal case FP_SUBNORMAL: cout << "Subnormal value \n"; break; // For the data to be normal case FP_NORMAL: cout << "Normal value \n"; break; // For the data to be invalid default: cout << "Invalid number \n"; } } // Driver code int main() { // Example 1 double a = 1.0 / 0.0; cout << "For 1.0/0.0: "; fpclassification(a); // Example 2 double b = 0.0 / 0.0; cout << "For 0.0/0.0: "; fpclassification(b); // Example 3 double c = -0.0; cout << "For -0.0: "; fpclassification(c); // Example 4 double d = 1.0; cout << "For 1.0: "; fpclassification(d); return 0; } |
For 1.0/0.0: Infinite Number For 0.0/0.0: Not a Number For -0.0: Zero For 1.0: Normal value
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- std::uniform_int_distribution reset() method in C++ with examples
- std::uniform_int_distribution min() method in C++ with examples
- std::uniform_int_distribution a() method in C++ with examples
- std::uniform_int_distribution max() method in C++ with examples
- std::uniform_int_distribution b() method in C++ with examples
- std::uniform_real_distribution b() method in C++ with Examples
- std::uniform_real_distribution min() method in C++ with Examples
- std::uniform_real_distribution max() method in C++ with Examples
- std::uniform_real_distribution a() method in C++ with Examples
- std::uniform_real_distribution reset() method in C++ with Examples
- tgamma() method in C/C++ with Examples
- Difference Between malloc() and calloc() with Examples
- Understanding "volatile" qualifier in C | Set 2 (Examples)
- Pointers in C/C++ with Examples
- strtok() and strtok_r() functions in C with examples
- memset() in C with examples
- std::mismatch() with examples in C++
- wcscpy() function in C++ with Examples
- wcscmp() function in C++ with Examples
- set_symmetric_difference in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

