Home

NaNs

NaN stands for Not a Number and refers to a special value used in floating-point arithmetic to represent undefined or unrepresentable results. It is part of the IEEE 754 standard, which defines how floating-point numbers are stored and manipulated in most modern computer systems.

In IEEE 754 binary floating-point formats, a NaN is indicated by an exponent of all ones and

NaN values arise from operations that have no well-defined numeric result, such as 0/0, ∞ − ∞, or the

A fundamental property of NaN is that it is not equal to any value, including itself. Comparisons

Practical use and language differences vary. JavaScript treats NaN as a numeric value and uses NaN !==

Overall, NaN serves as a standardized signaling mechanism for undefined results within floating-point computations, enabling error

a
nonzero
significand
(mantissa).
The
sign
bit
may
be
0
or
1.
NaNs
are
further
categorized
as
quiet
NaNs
(qNaN)
and
signaling
NaNs
(sNaN);
the
latter
may
trigger
floating-point
exceptions
on
certain
operations,
while
quiet
NaNs
propagate
through
calculations
without
signaling.
square
root
of
a
negative
number
in
real
arithmetic.
They
can
also
result
from
invalid
transformations
or
from
domain
errors
in
functions.
Once
generated,
NaN
typically
propagates
through
most
arithmetic
operations,
producing
another
NaN,
which
helps
detect
downstream
errors.
with
NaN
generally
yield
false,
so
languages
provide
special
checks
such
as
isnan
or
isNaN
to
determine
if
a
value
is
NaN.
NaN,
with
isNaN
and
Number.isNaN
for
checks.
Python
exposes
NaN
via
float('nan')
and
math.nan,
with
math.isnan
to
test.
C
and
C++
provide
NAN
or
nan()
macros
and
routines
like
isnan.
In
databases
and
numerical
libraries,
NaN
handling
is
influenced
by
the
specific
implementation
and
the
available
functions
for
numeric
checks
and
aggregations.
handling
and
debugging
while
preserving
numerical
workflows.