Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
isnormal() in C++ Programming
In this article we will be discussing the working, syntax and examples of isnormal() function in C++ STL.
Isnormal() is a function which comes under the <cmath> header file. This function is used to check whether the given number is a normal number or not.
What is a normal number?
A real number is known as a normal number if its base a number is neither zero, infinity, NAN or subnormal.
Syntax
bool isnormal(float num);
Parameters
The function accepts only one parameter which is num, of float type.
Return value
It returns 0 or 1, if the number is a normal number then the function returns 1 else 0.
Example
Input: isnormal(5.0); Output: 1 Input: isnormal(0.0); Output: 0
Example
#include <bits/stdc++.h>
using namespace std;
int main() {
//For Float
cout<<"\n For Float : ";
float var_1 = 5.89F;
//when value is other than zero
cout<<"check for isnormal(5.89F) : "<<isnormal(var_1);
//when value is zero
var_1 = 0.0F;
cout<<"\ncheck for isnormal(0.0F) : "<<isnormal(var_1);
//when its a infinite value by dividing it with 0.0
var_1 = 2.2F;
cout<<"\ncheck for isnormal(2.2F/0.0F) : "<<isnormal(var_1/0.0F);
//For double
cout<<"\n\n For Double : ";
double var_2 = 5.89;
//when value is other than zero
cout<<"check for isnormal(5.89) : "<<isnormal(var_2);
//when value is zero
var_2 = 0.0;
cout<<"\ncheck for isnormal(0.0) : "<<isnormal(var_2);
//when its a infinite value by dividing it with 0.0
var_2 = 2.2;
cout<<"\ncheck for isnormal(2.2/0.0) : "<<isnormal(var_2/0.0);
//For Long double
cout<<"\n\n For Long Double : ";
long double var_3 = 5.89;
//when value is other than zero
cout<<"check for isnormal(5.89) : "<<isnormal(var_3);
//when value is zero
var_3 = 0.0;
cout<<"\ncheck for isnormal(0.0) : "<<isnormal(var_3);
//when its a infinite value by dividing it with 0.0
var_3 = 2.2;
cout<<"\ncheck for isnormal(2.2/0.0) : "<<isnormal(var_3/0.0);
return 0;
}
Output
If we run the above code it will generate the following output −
For Float : check for isnormal(5.89F) : 1 check for isnormal(0.0F) : 0 check for isnormal(2.2F/0.0F) : 0 For Double : check for isnormal(5.89) : 1 check for isnormal(0.0) : 0 check for isnormal(2.2/0.0) : 0 For Long Double : check for isnormal(5.89) : 1 check for isnormal(0.0) : 0 check for isnormal(2.2/0.0) : 0
Advertisements