Python Glossary Русский

Python 3.15+mathfunction

math.isnormal()

checks

True if x is a normal floating-point number: finite, nonzero and not subnormal. Zero, infinity and NaN give False.

Syntax

math.isnormal(x)

Normal numbers keep the full precision of the mantissa; below sys.float_info.min (about 2.2e-308) come subnormal numbers, whose precision drops and whose arithmetic is noticeably slower on some CPUs. isnormal answers “is this an ordinary full-precision number?” with one check instead of a chain of isfinite, != 0 and a comparison with float_info.min.

Examples

import math, sys
print(math.isnormal(1.0), math.isnormal(0.0))  # → True False
print(math.isnormal(sys.float_info.min / 2))  # → False — субнормальное
print(math.isnormal(float('inf')))  # → False

See also

Open in the full glossarydocs.python.orgReport an inaccuracy