Math Fpclassify Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Fpclassify Function

Math Fpclassify Function

BLUF: Mastering Math Fpclassify Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Fpclassify Function

C++ is renowned for its efficiency. Learn how Math Fpclassify Function enables low-level control and high-performance computing in the tutorial below.

C++ Math fpclassify

The function will provide an integer value corresponding to one of the macro constants, based on the value of x.

value description
FP_INFINITE Positive or negative infinity
FP_NAN Not a Number
FP_ZERO Value of zero.
FP_SUBNORMAL Sub Normal value
FP_NORMAL Normal value

Syntax

Suppose a number is x. Syntax would be:

Example

int fpclassify(float x);
int fpclassify(double x);
int fpclassify(long double x);
int fpclassify(int x);

Parameter

x : The value that needs to be compared with one of the macro constants.

Return value

It provides the following integer values: FPINFINITE, FPNAN, FPZERO, FPSUBNORMAL, FP_NORMAL.

Example

Let's see the simple example.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    double d=1.0/0.0;
    switch(fpclassify(d))
    {
    case FP_INFINITE:
    cout<<"1.0/0.0 is a infinite number ";  
    break;
    case FP_NAN:
    cout<<"1.0/0.0 is Not a Number";
    break;
    case FP_ZERO:
    cout<<"1.0/0.0 is zero.";
    break;
    case FP_SUBNORMAL:
    cout<<"1.0/0.0 is a subnormal value";
    break;
    case FP_NORMAL:
    cout<<"1.0/0.0 is a normal value";
    break;
    default:
    cout<<"wrong number";
    }
    return 0;
}

Output:

Output

1.0/0.0 is a infinite number

In this instance, the fpclassify function identifies that x is an infinite value.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience