C++ std::isnormal() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
<cmath>

Definition

In C++, std::isnormal(x) is the strictest of the classification checks. It returns true only for ordinary numbers that are stored with full precision. Zero is not normal, and neither are infinity, NaN, and the tiny subnormal numbers.

A subnormal number is a value between zero and the smallest normal double, which is std::numeric_limits<double>::min(), about 2.2e-308. Subnormal numbers still work, but they lose digits of precision as they get smaller.

std::isnormal() is declared in <cmath> and is part of the group Classification and comparison. These tools ask what kind of number you have: normal, zero, infinite, or NaN. In C++ they are ordinary overloaded functions in std, not macros.

Syntax

Include <cmath> and call std::isnormal. Start with these lines.

C++
bool a = std::isnormal(1.5);     // true
bool b = std::isnormal(0.0);     // false (zero is not normal)
bool c = std::isnormal(1e-310);  // false (subnormal)
CallWhat it does
std::isnormal(1.5)An ordinary number. Returns true.
std::isnormal(0.0)Zero is not normal. Returns false.
std::isnormal(1e-310)Smaller than the smallest normal double, so subnormal. Returns false.

Write std:: in front, and include <cmath>. The function returns a bool, so use std::boolalpha to print true or false.

Library declarations
C++
bool isnormal(float x);
bool isnormal(double x);
bool isnormal(long double x);
bool isnormal(Integer x);   // for integer types

Parameters

ParameterDescription
xRequired. The number to test. It can be float, double, long double, or an integer type.

Return Value

Return ValueDescription
truex is a normal finite number and not zero.
falsex is zero, subnormal, infinity, or NaN.

C++ Examples

Example 1 — Test Several Values

Try a normal value, zero, the smallest subnormal value, the smallest normal value, infinity, and NaN.

C++
#include <cmath>
#include <iostream>
#include <limits>

int main() {
    std::cout << std::boolalpha;
    using L = std::numeric_limits<double>;

    std::cout << "1.5:        " << std::isnormal(1.5) << '\n';
    std::cout << "0.0:        " << std::isnormal(0.0) << '\n';
    std::cout << "denorm_min: " << std::isnormal(L::denorm_min()) << '\n';
    std::cout << "min():      " << std::isnormal(L::min()) << '\n';
    std::cout << "infinity:   " << std::isnormal(L::infinity()) << '\n';
    std::cout << "NaN:        " << std::isnormal(std::nan("")) << '\n';
    return 0;
}

How It Works

  1. using L = std::numeric_limits<double>; is a short name so each line stays easy to read.
  2. 1.5 is normal, and so is min(), the smallest normal double. Zero and denorm_min() (the smallest subnormal) are not.
  3. Infinity and NaN are not normal either, so only two of the six lines print true.

Example 2 — Just Below the Smallest Normal Number

Cut the smallest normal number in half and see how its class changes.

C++
#include <cmath>
#include <iostream>
#include <limits>

int main() {
    std::cout << std::boolalpha;
    double smallest = std::numeric_limits<double>::min();
    double half = smallest / 2;

    std::cout << "smallest normal: " << smallest << ", normal: " << std::isnormal(smallest) << '\n';
    std::cout << "half of it:      " << half << ", normal: " << std::isnormal(half) << '\n';
    return 0;
}

How It Works

  1. numeric_limits<double>::min() is the smallest positive normal double, 2.22507e-308.
  2. Half of it is 1.11254e-308. That is still a real number, and it is not zero, but it is below the normal range.
  3. So isnormal() is true for the first value and false for the half. This is the exact border of the normal range.

Example 3 — Halve a Number Until It Is Not Normal

Start at 1.0 and divide by 2 each time. Count the steps until the value stops being normal.

C++
#include <cmath>
#include <iostream>

int main() {
    double x = 1.0;
    int halvings = 0;

    while (std::isnormal(x)) {
        x /= 2;
        ++halvings;
    }
    std::cout << "Halvings until not normal: " << halvings << '\n';
    std::cout << "Value now: " << x << '\n';
    std::cout << "Is it zero? " << (x == 0.0) << '\n';
    return 0;
}

How It Works

  1. After n halvings x equals 2^-n. The smallest normal value is 2^-1022.
  2. The loop stops at the first value below that, which is 2^-1023. That needs 1023 halvings, and it is about 1.11254e-308.
  3. The value is not zero. It is a subnormal number: the numbers get smaller more slowly and lose precision before they finally reach zero. This is called gradual underflow.

Frequently Asked Questions

std::isnormal(x) returns true only if x is a normal number. It returns false for zero, subnormal numbers, infinity, and NaN.
true if x is a normal finite number, not zero. false if x is zero, subnormal, infinity, or NaN.
Zero has no normal form. A normal number is stored with a leading 1 bit and a non-zero exponent, and zero is stored specially. Use std::isfinite() if you want zero to count as valid.
std::numeric_limits<double>::min(), which is about 2.2250738585072014e-308. Anything smaller but not zero is subnormal.
Include <cmath> and write std::isnormal(). That always works and picks the C++ overloads. The global name ::isnormal often works too, but the standard does not promise it, and it may only take a double.

Next: isunordered()

Keep going through the <cmath> functions. Checks if x and y cannot be compared because one is NaN.

isunordered() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful