liveBook · Manning

Precision

As explained in Modern C, Third Edition

Precision is the number of significant binary digits available to represent a floating-point value in the C standard's restricted sense.

In C, `DBL_MANT_DIG` gives the precision of `double`: the number of binary digits used for its floating-point significand. It is typically 53. Precision describes a representation, not the accuracy of a particular calculation. section 5.7.8 section 5.8

In a simplified model, a floating-point value has a sign `s`, an exponent `e`, and `p` mantissa bits `f₁` through `fₚ`. Its value is `s × 2ᵉ × Σ(fₖ × 2⁻ᵏ)`. The exponent controls scale; `p` limits how many binary digits the representation retains. Both precision and exponent limits depend on the type. section 5.7.8

Three mantissa bits

Take `s = −1`, `e = −2`, and mantissa bits `101`. Their fractional value is `1/2 + 1/8 = 5/8`, so the represented value is `−2⁻² × 5/8 = −5/32`. A finite set of bits cannot retain every binary expansion; digits may be cut off, including during intermediate computations. section 5.7.8

Precision also has an integer meaning. For an unsigned type with precision `p`, bits `b₀` through `bₚ₋₁` represent `Σ(bᵢ × 2ⁱ)`. Its values therefore run from `0` through `2ᵖ − 1`; for unsigned types, precision equals width. Unlike an integer result without overflow, a floating-point result may be approximate. section 5.7.1 section 5.8

TAKEAWAY: Use the relevant type’s precision when reasoning about its limits.

  • Do not assume C prescribes one precision for every implementation of a basic type. section 5.2
  • For shifts, keep the right operand below the precision; bits shifted beyond an unsigned representation are dropped. section 5.7.3
  • For bit-set complement, the precision determines which bit positions belong to the complemented set. section 5.7.2

How Modern C, Third Edition covers it

How deep it goes
Derives unsigned ranges from bit positions and works through a simplified floating-point formula, without specifying every implementation’s type precision.
Examples
Uses a three-bit mantissa to calculate −5/32 and unsigned bit positions to establish the maximum 2ᵖ − 1.
What it assumes
Assumes familiarity with C types and arithmetic while defining the relevant binary digits and mantissa bits.
What you can do after
Evaluate/understand representable ranges and precision-dependent operations without confusing precision with computational accuracy.
How it connects
Connects precision to unsigned integers, floating-point exponents, mantissas, shift operators, and bit-set complement.

Also explained in

Compare how 9 books explain precision →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.