C++ isnormal()
In C++, the isnormal() function determines whether a floating-point number is normal, meaning it is non-zero, not subnormal, not infinite, and not NaN. It is useful when performing numerical computations that require standard floating-point numbers.
Syntax
bool isnormal(double x);
Or, alternatively:
bool isnormal(float x);
Or, alternatively:
bool isnormal(long double x);
Parameters:
x: The floating-point number (float,double, orlong double) to be checked.
Return value:
trueifxis a normal floating-point number.falseifxis zero, subnormal, infinite, or NaN.
Example 1: Checking normal and zero numbers
In this example, a normal number and zero are checked using isnormal(). The normal number returns true, while zero returns false:
#include <iostream>#include <cmath>int main() {double a = 5.0;double b = 0.0;std::cout << std::boolalpha;std::cout << "isnormal(a): " << std::isnormal(a) << "\n";std::cout << "isnormal(b): " << std::isnormal(b) << "\n";return 0;}
The output of this code is:
isnormal(a): trueisnormal(b): false
Codebyte Example: Checking subnormal, infinite, and NaN numbers
In this example, subnormal, infinite, and NaN numbers are checked. All of these are not considered normal, so isnormal() returns false for each:
Frequently Asked Questions
1. How to use not equal in C++?
The not equal operator in C++ is written as !=. It compares two values and returns true if they are not equal, otherwise false. Example:
#include <iostream>int main() {int a = 5, b = 10;if (a != b) {std::cout << "a and b are not equal\n"; // outputs: a and b are not equal}return 0;}
2. What is isdigit() in C++?
The isdigit() function checks if a character is a decimal digit ('0'–'9'). It is declared in <cctype> or <ctype.h> and returns a non-zero value (true) if the character is a digit, otherwise 0 (false).
3. What are the four types of functions in C++?
The four types of functions in C++ based on parameters and return type are:
- Function with no arguments and no return value
- Function with arguments and no return value
- Function with no arguments but returns a value
- Function with arguments and returns a value
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
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