liveBook · Manning

Floating-point value

As explained in Grokking Statistics

A floating-point value is a computer representation of a real number using a significand and an exponent, subject to finite precision.

A floating-point value represents a real number with a decimal part, such as 6.73 or 5.32. It helps describe measurements that do not fit neatly into whole-number counts: half a gallon of milk or part of a mile on a bike ride. section 2.11

Floating-point values can represent rational numbers, including fractions, finite decimals, and repeating decimals. They can also approximate irrational numbers such as pi, e, and the square root of 2. Because computers reserve a fixed number of bits—typically 64—for the digits, these values have limited precision. section 2.11 section 2.8

Practical consequences include:

  • Expect small rounding errors when representing or calculating with irrational numbers. section 2.11
  • Use symbolic libraries such as SymPy when exact symbolic values matter. section 2.11
  • Watch for floating-point underflow when multiplying very small values; numerical libraries such as NumPy may provide suitable safeguards. section 2.11

Coffee measurements

A coffee scale may record whole grams, such as 27, even though the amount of coffee is conceptually continuous and could fall between those measurements. Treating the variable as a floating-point real number supports a continuous distribution, such as a normal distribution. section 4.3

import math

irrational_numbers = [ math.pi , math.sqrt(2), math.e ]

for x in irrational_numbers:
  print(x)

# 3.141592653589793
# 1.4142135623730951
# 2.718281828459045

Inspect how Python displays approximations of pi, the square root of 2, and e. section 2.11

How Grokking Statistics covers it

How deep it goes
Defines real, rational, and irrational values, then explains finite precision and underflow without deriving floating-point internals.
Examples
Uses decimal measurements, fractions, Python approximations of pi and e, and coffee-scale readings.
What it assumes
Assumes basic familiarity with numbers while introducing natural numbers, integers, Booleans, rational numbers, and irrational numbers.
What you can do after
Apply via Python by recognizing approximate values, anticipating precision errors, and choosing symbolic or numerical techniques.
How it connects
Connects real numbers with rational numbers, irrational numbers, continuous distributions, normal distributions, and numerical data types.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Statistics. The section links point to the parts of the book it draws on.