Python math.isnormal() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Recent Python

Definition

math.isnormal(x) returns True if x is a normal floating-point number: finite, nonzero, and with magnitude at least sys.float_info.min (2**-1022, about 2.225e-308).

Zero (0.0, -0.0), tiny subnormal floats, infinities, and NaN all return False. Check the official docs for your exact Python release, and guard with hasattr(math, "isnormal") if supporting older Python.

math.isnormal() is a function in Python's standard math module: import it with import math and call math.isnormal(...), or import the name directly with from math import isnormal. New in recent Python versions (3.15 at the time of writing; check your version with import sys; print(sys.version)).

Syntax

Import math (and check hasattr for portability across Python versions).

python
import math

ok = math.isnormal(x)
CallWhat it does
math.isnormal(1.0)Returns True.
math.isnormal(0.0)Returns False (zero is not normal).
math.isnormal(1e-310)Returns False (subnormal float).
math.isnormal(float("inf"))Returns False.

On Python versions without math.isnormal(), the exact IEEE 754 check is math.isfinite(x) and abs(x) >= sys.float_info.min.

Function signatures
python
math.isnormal(x, /)
# recent Python addition (3.15 at writing); returns bool

Parameters

ParameterDescription
xRequired positional real number (int or float).

Return Value

Return ValueDescription
boolTrue if x is normal, else False.

Python Examples

Example 1 — Check Normal, Subnormal, Zero, and Inf Portably

Use hasattr(math, "isnormal") with a sys.float_info.min fallback so output stays identical across versions.

python
import math
import sys


def is_normal(x):
    if hasattr(math, "isnormal"):
        return math.isnormal(x)
    return math.isfinite(x) and abs(x) >= sys.float_info.min


samples = [1.0, sys.float_info.min, 1e-310, 0.0, math.inf, math.nan]
for val in samples:
    print(f"{val!r:>23} -> {is_normal(val)}")

How It Works

  1. Minimum normal boundary. sys.float_info.min (2**-1022) is the smallest positive normal float and returns True.
  2. Subnormals drop out. 1e-310 is nonzero and finite, yet smaller than float_info.min, so it returns False.
  3. Zero is not normal. Both 0.0 and non-finite values return False.

Example 2 — Step Across the Normal-to-Subnormal Boundary

Shift sys.float_info.min down by one binary bit with math.ldexp() to watch normal classification flip.

python
import math
import sys

is_norm = getattr(
    math,
    "isnormal",
    lambda x: math.isfinite(x) and abs(x) >= sys.float_info.min,
)

edge = sys.float_info.min
half_edge = math.ldexp(edge, -1)
print("at min  :", is_norm(edge))
print("half min:", is_norm(half_edge))

How It Works

  1. Exact boundary test. At sys.float_info.min, the implicit leading IEEE 754 bit is still 1 (True).
  2. Single bit down enters subnormal. Halving with ldexp(edge, -1) crosses into subnormal precision (False).
  3. Portable attribute lookup. getattr uses native math.isnormal when present.

Example 3 — Detect math.isnormal() Support at Runtime

Print explicit output depending on whether your Python version provides math.isnormal().

python
import math
import sys

test_vals = [-4.5, 0.0, 1e-315]
if hasattr(math, "isnormal"):
    print("math.isnormal:", [math.isnormal(v) for v in test_vals])
else:
    res = [
        math.isfinite(v) and abs(v) >= sys.float_info.min
        for v in test_vals
    ]
    print("fallback:", res)

How It Works

  1. Runtime branch. Checking hasattr(math, "isnormal") lets code opt into the native helper without crashing on older Python.
  2. Identical boolean vector. Both branches classify -4.5 as normal and reject zero and subnormal 1e-315.
  3. Inspect version if unsure. Run import sys; print(sys.version) to verify your interpreter release.

Frequently Asked Questions

It is new in recent Python versions (3.15 at the time of writing); run import sys; print(sys.version) or check hasattr(math, "isnormal") on your interpreter.
IEEE 754 defines zero as its own category separate from normal nonzero numbers, so zero returns False.
sys.float_info.min (2**-1022, roughly 2.2250738585072014e-308). Any nonzero number smaller than that is subnormal.
Use math.isfinite(x) and abs(x) >= sys.float_info.min.
isfinite(x) returns True for zero and subnormals, whereas isnormal(x) returns True only for nonzero normal numbers.

Next: math.isqrt()

Return the integer square root of a non-negative integer.

isqrt() →

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