C++ fpclassify()

Priyanshjain10's avatar
Published Feb 11, 2026

The fpclassify() function in C++ returns an integer value indicating the classification of a floating-point number. It categorizes values as normal, subnormal, zero, infinite, or NaN (Not-a-Number). The function is available through the <cmath> header.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours

Syntax

fpclassify(x)

Parameters:

  • x: A floating-point value (can be float, double, or long double).

Return value:

The fpclassify() function returns one of the following integer constants:

  • FP_INFINITE: The value is positive or negative infinity.
  • FP_NAN: The value is NaN (Not-a-Number).
  • FP_ZERO: The value is zero.
  • FP_SUBNORMAL: The value is a subnormal (denormalized) number.
  • FP_NORMAL: The value is a normal finite non-zero number.

Example

The following example demonstrates various classifications using fpclassify():

#include <iostream>
#include <cmath>
using namespace std;
int main() {
double normal = 1.5;
double zero = 0.0;
double inf = INFINITY;
double nan = NAN;
cout << "Classification of " << normal << ": ";
if (fpclassify(normal) == FP_NORMAL) {
cout << "Normal" << endl;
}
cout << "Classification of " << zero << ": ";
if (fpclassify(zero) == FP_ZERO) {
cout << "Zero" << endl;
}
cout << "Classification of inf: ";
if (fpclassify(inf) == FP_INFINITE) {
cout << "Infinite" << endl;
}
cout << "Classification of nan: ";
if (fpclassify(nan) == FP_NAN) {
cout << "NaN" << endl;
}
return 0;
}

The output of this code is:

Classification of 1.5: Normal
Classification of 0: Zero
Classification of inf: Infinite
Classification of nan: NaN

Codebyte Example

The following runnable example shows how to use fpclassify() with different values:

Code
Output

All contributors

Learn C++ on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours