The Maths You Actually NeedLesson 76 of 76

Module 8 · Numbers inside a machine

NaN, Inf, and the five numbers to print about any tensor

In this lesson

  • 9 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 10 of 10 in this chapter

This chapter’s goalPredict from the bit layout of float32, fp16 and bf16 which computation will overflow, underflow or lose its digits, explain why a long sum drifts and how to fix it, quantise a weight to int8 by hand and say what an outlier does to the rest of the tensor, derive the initialisation scale that keeps variance constant through a layer, and diagnose a NaN in training back to the operation that produced it.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 7Free · no account needed
Lesson steps

Two special values, with rules

The floating-point standard reserves bit patterns for two things that are not numbers. Inf, positive or negative, is what overflow produces, and what division of a non-zero number by zero produces. NaN, “not a number”, is what you get when the arithmetic has no defensible answer:

Text
0 / 0          NaN
Inf − Inf      NaN
0 × Inf        NaN
Inf / Inf      NaN
sqrt(−1)       NaN
log(−1)        NaN
log(0)         −Inf   (not NaN, and the distinction is useful)

Both propagate. Any operation with a NaN input gives NaN, and most operations with Inf give Inf or NaN. One NaN in a gradient becomes a NaN in every weight it touches after one optimiser step, and then in every activation, and then in the loss. A NaN in training is therefore rarely where it appears; it is downstream of its origin, and the work is tracing it back.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Funke, your AI tutor

How to cite: Addaly (2026) ‘NaN, Inf, and the five numbers to print about any tensor’, in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/nan-inf-and-the-statistics-of-a-tensor (Accessed: 29 November 2026).