isnormal() in C++

This function is defined in <cmath.h> . By using isnormal() function, we determines that whether the given number is normal (neither zero, infinite nor NAN) or not. This function returns 1 if the number is normal else return zero.

Syntax:

bool  isnormal(float x);

or



bool  isnormal(double x); 

or

bool  isnormal(long double x); 

Parameters: This functions takes a mandatory parameter x which represents the floating point value.

Returns: If the given value is normal then the function returns 1 otherwise the function returns zero.

Below program illustrate the isnormal() function in C++:

Example 1:- To show with float value

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to demonstrate
// example of isnormal() function.
  
#include <bits/stdc++.h>
  
using namespace std;
  
int main()
{
  
    float f = 7.0F;
  
    // check for non-zero value
    cout << "isnormal(7.0) is = " << isnormal(f) << endl;
  
    // check for zero
    f = 0.0F;
    cout << "isnormal(0.0) is = " << isnormal(f) << endl;
  
    // check for infinite value
    f = 9.2F;
    cout << "isnormal(9.2/0.0) is = " << isnormal(f / 0.0) << endl;
  
    return 0;
}

chevron_right


Output:

isnormal(7.0) is = 1
isnormal(0.0) is = 0
isnormal(9.2/0.0) is = 0

Example 2:- To show with double value

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to demonstrate
// example of isnormal() function.
  
#include <bits/stdc++.h>
  
using namespace std;
  
int main()
{
  
    double f = 7.0;
  
    // check for non-zero value
    cout << "isnormal(7.0) is = " << isnormal(f) << endl;
  
    // check for zero
    f = 0.0;
    cout << "isnormal(0.0) is = " << isnormal(f) << endl;
  
    // check for infinite value
    f = 9.2;
    cout << "isnormal(9.2/0.0) is = " << isnormal(f / 0.0) << endl;
  
    return 0;
}

chevron_right


Output:

isnormal(7.0) is = 1
isnormal(0.0) is = 0
isnormal(9.2/0.0) is = 0

Example 3:- To show with long double value

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to demonstrate
// example of isnormal() function.
  
#include <bits/stdc++.h>
  
using namespace std;
  
int main()
{
  
    long double f = 7.0;
  
    // check for non-zero value
    cout << "isnormal(7.0) is = " << isnormal(f) << endl;
  
    // check for zero
    f = 0.0;
    cout << "isnormal(0.0) is = " << isnormal(f) << endl;
  
    // check for infinite value
    f = 9.2;
    cout << "isnormal(9.2/0.0) is = " << isnormal(f / 0.0) << endl;
  
    return 0;
}

chevron_right


Output:

isnormal(7.0) is = 1
isnormal(0.0) is = 0
isnormal(9.2/0.0) is = 0


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.