fpclassify() in C++
In this tutorial, we will learn about fpclassify function in C++ also here will be an example of an illustration of the code. Thus, to understand the concept clearly please read the content.
fpclassify() in C++
The fpclassify function/ Method is present in Cmath library. So let us see the syntax for the fpclassify function.
Syntax

Note–
The value z which will be matched with one of the macro constants. Now, since the return type is an integer so this function will return some value It returns the following values:
- FP_INFINITE: Positive or negative infinity.
- FP_ZERO: Value of zero.
- FP_NAN: Not a number
- FP_SUBNORMAL: Subnormal value.
- FP_NORMAL: Normal value.
Thus let us see the code for this fclassify function in c++
CODE
#include <iostream>
#include <math.h>
using namespace std;
void fpfind(double z)
{
switch (fpclassify(z)) {
// z will be compared to macros and based on that it will return a value which will be checked in this switch case
case FP_INFINITE:
cout << "Infinite Number \n";
break;
case FP_NAN:
cout << "Not a Number \n";
break;
case FP_ZERO:
cout << "Zero \n";
break;
case FP_SUBNORMAL:
cout << "Subnormal value \n";
break;
case FP_NORMAL:
cout << "Normal value \n";
break;
// For the data to be invalid
default:
cout << "Invalid number \n";
}
}
int main()
{
double a = 1.0 / 0.0;
cout << "For 1.0/0.0: ";
fpfind(a);
double b = 0.0 / 0.0;
cout << "For 0.0/0.0: ";
fpfind(b);
double c = -0.0;
cout << "For -0.0: ";
fpfind(c);
double d = 1.0;
cout << "For 1.0: ";
fpfind(d);
return 0;
}
Please check the output from below.
output:
For 1.0/0.0: Infinite Number For 0.0/0.0: Not a Number For -0.0: Zero For 1.0: Normal value -------------------------------- Process exited after 8.58 seconds with return value 0 Press any key to continue . . .
Also read: Set of vectors in C++
Leave a Reply