Mathematical Foundations

VIII.5 · Numerical Computing

When does a finite value leave a format’s range?

Follow one exact value through four explicitly emulated formats. Separate normal values, subnormals, numerical zero and overflow infinity from their mathematical origins.

Follow one exact value across four ranges

Interchange format (software rounding)

Sign (s)

0

Exponent (5 bits)

00000

Fraction (10 bits; normal values have an implicit leading 1)

0000000010

FP16 / binary16: subnormal, sign 0; Software-emulated FP16; not actual hardware operations. Direct nearest rounding, ties to even; all four formats retain subnormals. A formatted decimal is distinct from the bits and exact rational.

Stored classification
subnormal
Sign bit
0
Encoded exponent
0
Encoded fraction integer
2
Exact stored rational
1/8388608
Formatted stored display
0.00000011920928955
Spacing in the stored binade
1/16777216
Exact signed representation error
12589/655360000000
Absolute representation error
12589/655360000000
Relative representation error (nonzero input)
12589/65536

= exact rationals or classifications · ≈ a formatted numerical display. Exceptional values retain their stated meaning.

x=(−1)s(1+F 2−p) 2E−b,0<E<2e−1x=(-1)^s(1+F\,2^{-p})\,2^{E-b},\quad 0<E<2^e-1
xsub=(−1)sF 21−b−p,E=0x_{\mathrm{sub}}=(-1)^sF\,2^{1-b-p},\quad E=0
Ea=∣x^−x∣,Er=Ea/∣x∣ (x≠0)E_a=|\widehat x-x|,\quad E_r=E_a/|x|\ (x\ne0)
Adjacent representable values; binade boundaries can have asymmetric gaps.
neighborexact valueformatted display
previous1/16777216≈ 0.00000005960464478
stored1/8388608≈ 0.00000011920928955
next3/16777216≈ 0.00000017881393433
Same exact intended input, independently rounded to each format. FP16/BF16 are emulated.
formatprecision bitsnormal exponentskinddisplaymin normalmin subnormal
binary6453-1022 to 1023normal≈ 0.00000012^(-1022)2^(-1074)
binary3224-126 to 127normal≈ 0.000000100000001172^(-126)2^(-149)
FP16 / binary1611-14 to 15subnormal≈ 0.000000119209289552^(-14)2^(-24)
BF16 / bfloat168-126 to 127normal≈ 0.000000100117176772^(-126)2^(-133)

Read the intended input

Decimal text enters as an exact rational; signed zero and special values retain their classification.

Inspect the recorded values\text{Inspect the recorded values}
Actual intermediate values; = exact rationals, ≈ binary64 displays.
quantityvalue
input1/10000000

Exact decimal text, at most 420 characters; exponent in [-400,400].

Edit the exact decimal exponent and inspect classifications and actual stored values across all four software-emulated layouts.

Intuition: a ruler has endpoints

Precision describes spacing; range describes which scales remain representable. A format can have adequate precision near one but no representable normal value at the scale a calculation needs. Move the exact decimal exponent in the input and compare all four results in the same table.

The first range transition near zero is usually from normal to subnormal. Subnormals retain a constant absolute spacing rather than a full normal significand. A smaller magnitude eventually rounds to zero. At the other end, nearest/ties-even rounding eventually selects infinity instead of a finite representable value. Those are computational outcomes for an intended value, not changes to the intended mathematics.

Definition: three finite scales

With exponent bias b and p fraction bits, the smallest positive normal value, smallest positive subnormal value and largest finite value are

xmin⁡,normal=21−b,xmin⁡,sub=21−b−p,x_{\min,\mathrm{normal}}=2^{1-b},\qquad x_{\min,\mathrm{sub}}=2^{1-b-p}, xmax⁡=(2−2−p)2b.x_{\max}=(2-2^{-p})2^b.

These formulas apply to the four binary interchange layouts in this explorer. Nearest rounding gives zero at exactly half the least positive subnormal, because zero is the even endpoint. The midpoint above the largest finite significand is the overflow threshold:

xoverflow tie=2b+1−2b−p−1.x_{\mathrm{overflow\ tie}}=2^{b+1}-2^{b-p-1}.

At that tie, the carry selects infinity. Below it, some exact values larger than the largest finite value still round to that largest finite value. Merely exceeding the maximum is therefore not a complete nearest-rounding overflow rule.

Mechanics: gradual underflow and explicit origins

The exact decimal enters as a rational and is rounded separately to every format. The table includes precision, normal exponent range, classification, formatted stored value and both minimum scales. The selected format also exposes its fields and actual neighbors.

A finite nonzero intended input that rounds to zero is labelled as numerical underflow to zero. Intended zero is labelled as mathematical zero. An entered infinity and a finite input that overflows have different origins. NaN remains an exceptional encoding with no real value. Error measurements are undefined for non-finite results instead of silently becoming a finite-looking number.

Here, “underflow” describes tiny-value representation and possible loss. The explorer does not simulate an IEEE exception flag: such a flag can depend on tininess detection and inexactness, and an exactly represented subnormal need not raise it.

Derivation: why precision fades among subnormals

Normal spacing follows the binade. Subnormal spacing remains

Δ=21−b−p.\Delta=2^{1-b-p}.

At a tiny nonzero value kΔ, half a spacing is a relative scale of roughly 1/(2k). As k becomes small, the available relative accuracy deteriorates even though the absolute grid spacing stays fixed. This is gradual underflow: the values fade through a smaller effective significand rather than immediately jumping from the least normal number to zero.

FP16 has least normal 2−142^{-14} and least subnormal 2−242^{-24}. BF16 shares binary32’s normal lower exponent −126, but its least subnormal is 2−1332^{-133} rather than binary32’s 2−1492^{-149}. Sharing exponent bits does not make these ranges identical.

Worked example: one decimal, four classifications

For exact 1e-7, FP16 stores a subnormal near 2−232^{-23}; BF16, binary32 and binary64 store normal values. For 1e-50, both 16-bit formats and binary32 round to zero, while binary64 remains normal. Intended zero would instead be exactly zero in every format.

For 1e40, FP16, BF16 and binary32 overflow to infinity while binary64 remains finite. The all-overflow preset uses 1e400: its intended rational is finite, but every displayed interchange format overflows. Calling that input a mathematical infinity would be incorrect.

FP16’s midpoint above its maximum finite value is 65520. Under the specified rounding policy it overflows. The exact midpoint below its least subnormal is 2−252^{-25} and rounds to zero. A negative tiny input retains a negative-zero encoding when its magnitude rounds away.

Worked example: Follow one exact value across four ranges

Sign (s)

0

Exponent (5 bits)

00000

Fraction (10 bits; normal values have an implicit leading 1)

0000000010

FP16 / binary16: subnormal, sign 0; Software-emulated FP16; not actual hardware operations. Direct nearest rounding, ties to even; all four formats retain subnormals. A formatted decimal is distinct from the bits and exact rational.

Stored classification
subnormal
Sign bit
0
Encoded exponent
0
Encoded fraction integer
2
Exact stored rational
1/8388608
Formatted stored display
0.00000011920928955
Spacing in the stored binade
1/16777216
Exact signed representation error
12589/655360000000
Absolute representation error
12589/655360000000
Relative representation error (nonzero input)
12589/65536

= exact rationals or classifications · ≈ a formatted numerical display. Exceptional values retain their stated meaning.

x=(−1)s(1+F 2−p) 2E−b,0<E<2e−1x=(-1)^s(1+F\,2^{-p})\,2^{E-b},\quad 0<E<2^e-1
xsub=(−1)sF 21−b−p,E=0x_{\mathrm{sub}}=(-1)^sF\,2^{1-b-p},\quad E=0
Ea=∣x^−x∣,Er=Ea/∣x∣ (x≠0)E_a=|\widehat x-x|,\quad E_r=E_a/|x|\ (x\ne0)
Adjacent representable values; binade boundaries can have asymmetric gaps.
neighborexact valueformatted display
previous1/16777216≈ 0.00000005960464478
stored1/8388608≈ 0.00000011920928955
next3/16777216≈ 0.00000017881393433
Same exact intended input, independently rounded to each format. FP16/BF16 are emulated.
formatprecision bitsnormal exponentskinddisplaymin normalmin subnormal
binary6453-1022 to 1023normal≈ 0.00000012^(-1022)2^(-1074)
binary3224-126 to 127normal≈ 0.000000100000001172^(-126)2^(-149)
FP16 / binary1611-14 to 15subnormal≈ 0.000000119209289552^(-14)2^(-24)
BF16 / bfloat168-126 to 127normal≈ 0.000000100117176772^(-126)2^(-133)

Read the intended input

Decimal text enters as an exact rational; signed zero and special values retain their classification.

Inspect the recorded values\text{Inspect the recorded values}
Actual intermediate values; = exact rationals, ≈ binary64 displays.
quantityvalue
input1/10000000

Select the recorded intermediate values. Previous, next and direct replay navigation preserve immutable numerical history.

Executable reference code

The standard-library example uses the direct exact converter from the representation chapter, classifies all four emulated results and checks literal boundary values. NumPy demonstrates real dtype conversions on bounded ordinary range probes with expected warnings handled locally. BF16 remains software emulation because this environment’s core NumPy dtype set does not supply native BF16.

code/python/overflow_underflow.py
"""Exact intended range probes; all four conversions are software emulated."""
from fractions import Fraction
from floating_point_representation import FORMATS,convert,exact
if __name__ == '__main__':
    for text in ['1', '1e-7', '1e-50', '1e40', '1e400', '0', '-0']:
        for name,(e,p,b) in FORMATS.items():
            bits=convert(text,name);exp=(bits>>p)&(2**e-1);fraction=bits%(2**p)
            kind='infinity' if exp==2**e-1 else 'normal' if exp else 'subnormal' if fraction else 'zero'
            print(text,name,kind,exact(bits,name))
    assert convert('65520','fp16')==0x7c00
    assert convert('0.0000000298023223876953125','fp16')==0
    assert exact(convert('0.000000059604644775390625','fp16'),'fp16')==Fraction(1,2**24)
code/python/overflow_underflow_numpy.py
import numpy as np
from floating_point_representation import convert,exact
if __name__ == '__main__':
    with np.errstate(over='ignore',under='ignore',invalid='ignore'):
        for dtype in (np.float16,np.float32,np.float64):
            values=np.array(['1e-7','1e-50','1e40','0','-0'],dtype=dtype)
            print(dtype.__name__,values,'finite',np.isfinite(values),'zero',values==0,'sign',np.signbit(values))
        assert np.float16('1e-50')==0 and np.isinf(np.float32('1e40'))
        assert np.float64('1e-50')!=0 and np.isfinite(np.float64('1e40'))
    print('BF16 emulated:',exact(convert('1e-50','bf16'),'bf16'))

Explore: distinguish a zero from a lost value

Compare the underflowed-zeros and mathematical-zero presets before reading their explanation. The bit pattern alone can be the same, yet the intended input differs. Use the exact input record to determine which origin applies.

Edit a decimal exponent one step at a time near a range transition. Then select the FP16 subnormal preset in the representation chapter and inspect adjacent spacing. Enter NaN and Infinity here to compare safe exceptional-value handling with a finite input that overflows. Domain-valid real mathematics and finite computer storage are different requirements.

Common mistakes and counterexamples

A zero probability can be a model’s exact zero mass, a tiny positive probability rounded to zero, or an undefined computation mistakenly propagated. These meanings must not share one silent repair. A logarithm of a mathematically zero probability has an extended-value meaning that differs from taking log after a positive probability underflows.

A subnormal is nonzero and finite. Overflow infinity is not evidence that the true finite mathematical value is unbounded. NaN should not be sorted as a large value or allowed to silently bypass a numerical diagnostic.

Numerical considerations

The conversion model implements gradual underflow and nearest/ties-even for every supported layout. FP16 and BF16 are explicitly emulated, and actual hardware may flush subnormals or select a different rounding mode. No hardware exception flags or performance claims are simulated.

Direct rational conversion avoids unintended double rounding. Important boundary examples include half-subnormal ties, the normal/subnormal carry, signed zero, maximum finite values and overflow ties. Subsequent algorithms still need guards for exceptional intermediates: a finite input can yield an infinite product long before its final mathematical expression would overflow.

Engineering and ML connections

Range failures motivate rescaling, logarithmic representations and carefully bounded loss scaling. A small gradient can be scaled before low-precision storage, while a large scaled gradient may overflow instead. The next chapter shows the actual intermediates and limitations; scaling is a numerical trade-off whose valid operating range must be recorded.

Inspect the corresponding representation and error policy before interpreting a computed value.

Exercises

Predict first, then calculate or test the stated claim. Every answer includes corrective feedback and a worked solution.

calculation

Least FP16 normal

FP16 has bias 15. Give its least positive normal value as a fraction.

calculation

Subnormal spacing

FP16 has 10 fraction bits. Give its constant positive subnormal spacing.

calculation

Half a subnormal

Round exactly 2^−25 to FP16 under nearest/ties-even.

explanation

Finite overflow origin

An exact finite input 1e400 rounds to infinity in every supported format. What does that establish?

Choose one answer

explanation

Normal versus subnormal

Which description of a subnormal is correct?

Choose one answer

Summary and checkpoints

State the three finite range formulas and the nearest-rounding boundary rules. Explain gradual underflow, distinguish intended zero from numerical zero and finite-input overflow from entered infinity, and compare FP16, BF16 and binary32 without assuming identical ranges.

The map of the book

97 of 97 chapters written · eight Parts

demo Foundation demo Try the live vector example Open as a page

Part I

Mathematical Language

The notation and mental objects everything else uses.

9 of 9 chapters written

  1. I.1 Scalars, quantities, units, powers and roots available
  2. I.2 Coordinates and points available
  3. I.3 Vectors: components, magnitude, and direction reference chapter available
  4. I.4 Algebraic expressions, equations and inequalities available
  5. I.5 Functions as input → transformation → output available
  6. I.6 Essential function families available
  7. I.7 Sets, intervals, and relations available
  8. I.8 Indexed quantities and summation available
  9. I.9 The notation map for ML available

Part II

Linear Algebra

Matrices as transformations: the strongest foundation in the book.

19 of 19 chapters written

  1. II.1 Vector addition and subtraction available
  2. II.2 Scalar multiplication and vector scaling available
  3. II.3 Norms, magnitude, and normalization available
  4. II.4 Dot product, angle, and orthogonality available
  5. II.5 Projection and distance to a direction available
  6. II.6 Linear combinations and span available
  7. II.7 Linear independence, basis, and coordinates available
  8. II.8 Matrices as linear transformations available
  9. II.9 Matrix × vector available
  10. II.10 Matrix × matrix as composition available
  11. II.11 Transpose and orthogonality available
  12. II.12 Determinant: orientation and area/volume scaling available
  13. II.13 Linear systems as intersecting constraints available
  14. II.14 Gaussian elimination and row operations available
  15. II.15 Rank and invertibility available
  16. II.16 Inverse matrices available
  17. II.17 Eigenvalues and eigenvectors available
  18. II.18 Orthogonal bases and least-squares geometry available
  19. II.19 Singular Value Decomposition available

Part III

Calculus

Change, local approximation, and sensitivity made visible.

15 of 15 chapters written

  1. III.1 Limits through approach available
  2. III.2 Continuity and local behavior available
  3. III.3 Derivative as secant → tangent available
  4. III.4 Derivative as rate of change and local linear model available
  5. III.5 Derivative rules available
  6. III.6 Chain rule available
  7. III.7 Multivariable functions and partial derivatives available
  8. III.8 Gradient and directional derivatives available
  9. III.9 Jacobian available
  10. III.10 Computational graphs and automatic differentiation available
  11. III.11 Hessian and curvature available
  12. III.12 Integrals as accumulation available
  13. III.13 Fundamental derivative/integral connection available
  14. III.14 Numerical differentiation available
  15. III.15 Numerical integration available

Part IV

Probability

Uncertainty through sample spaces, evidence, and repetition.

16 of 16 chapters written

  1. IV.1 Random experiments, outcomes, and sample spaces available
  2. IV.2 Events and probability mass available
  3. IV.3 Counting and finite probability where needed available
  4. IV.4 Conditional probability as restricted sample space available
  5. IV.5 Independence available
  6. IV.6 Bayes' theorem as probability-mass update available
  7. IV.7 Random variables available
  8. IV.8 PMF, PDF, and CDF available
  9. IV.9 Bernoulli and Binomial distributions available
  10. IV.10 Uniform and Gaussian distributions available
  11. IV.11 Expectation available
  12. IV.12 Variance and standard deviation available
  13. IV.13 Joint, marginal, and conditional distributions available
  14. IV.14 Covariance and correlation available
  15. IV.15 Law of Large Numbers available
  16. IV.16 Central Limit Theorem available

Part V

Statistics

From observed data to estimates, intervals, and likelihood.

10 of 10 chapters written

  1. V.1 Data summaries: mean, median, mode available
  2. V.2 Spread: variance, standard deviation, robust interpretation available
  3. V.3 Population, sample, and sampling variability available
  4. V.4 Estimators and estimation available
  5. V.5 Confidence intervals through repeated sampling available
  6. V.6 Covariance matrices and multivariate spread available
  7. V.7 Regression fundamentals available
  8. V.8 Likelihood available
  9. V.9 Maximum Likelihood Estimation available
  10. V.10 Maximum A Posteriori estimation available

Part VI

Optimization

Learning as repeated parameter updates governed by an objective.

10 of 10 chapters written

  1. VI.1 Objective functions and optimization landscapes available
  2. VI.2 Local vs global optima and stationary points available
  3. VI.3 Convexity available
  4. VI.4 Gradient descent flagship chapter available
  5. VI.5 Learning rate and convergence behavior available
  6. VI.6 Momentum available
  7. VI.7 Stochastic and mini-batch gradient descent available
  8. VI.8 Adam intuition available
  9. VI.9 Constraints and projected/penalized intuition available
  10. VI.10 Numerical stopping and optimization diagnostics available

Part VII

Information Theory

Logarithms, entropy, and the loss behind token prediction.

8 of 8 chapters written

  1. VII.1 Logarithms and log probabilities in computation available
  2. VII.2 Self-information available
  3. VII.3 Entropy available
  4. VII.4 Cross entropy and negative log-likelihood available
  5. VII.5 KL divergence available
  6. VII.6 Logits and softmax available
  7. VII.7 Numerical stability: log-sum-exp and stable softmax available
  8. VII.8 From token logits to language-model loss available

Part VIII

Numerical Computing

Why equivalent expressions behave differently on real machines.

10 of 10 chapters written

  1. VIII.1 Floating-point representation available
  2. VIII.2 Rounding and representation error available
  3. VIII.3 Error propagation and conditioning available
  4. VIII.4 Catastrophic cancellation available
  5. VIII.5 Overflow and underflow available
  6. VIII.6 Stable algorithms available
  7. VIII.7 Numerical linear algebra realities available
  8. VIII.8 Sparse matrices and sparse structure available
  9. VIII.9 Vectorized computation available
  10. VIII.10 Reproducibility, random seeds, and nondeterminism available