liveBook · Manning

Precision

As explained in Modern C

Precision is the C-standard property that constrains the number of distinguishable or representable digits and thereby the valid range of a type.

A 16-bit unsigned value

For an unsigned type with precision p = 16, the value 240 has bits 4, 5, 6, and 7 set. Its maximum value is 2^16 − 1, or 65535; 65536 is the first value outside its range. section 5.7.1

Precision describes a property of a type, not the accuracy of a floating-point computation. C constrains the precision of its basic types but does not prescribe a single precision for each: the actual values depend on the implementation. section 5.2

For an integer type, precision p is the number of bits used to represent nonnegative values. Its maximum is 2^p − 1. For an unsigned type, the representable values run from zero to that maximum, and precision determines the type’s arithmetic. Limits such as UINT_MAX are available in <limits.h>. section 5.7.1

Precision also matters when an unsigned value is interpreted as a bit set. The possible bit positions run from 0 through p − 1, so a complement depends on p. In a left shift, bits that do not fit are omitted; the shift count must be less than the precision of the operand’s type. section 5.7.2 section 5.7.3

Shifting the 16-bit value

For a 16-bit unsigned shift operand, 240 << 2 gives 960. Shifting 240 left by 9 would place a bit at position 16, which does not fit; the remaining bits give 57344. section 5.7.3

In a simplified floating-point representation, precision p is the number of mantissa bits. The exponent bounds also depend on the type. For double, DBL_MANT_DIG, DBL_MIN_EXP, and DBL_MAX_EXP expose these properties; a typical DBL_MANT_DIG is 53. section 5.7.7

TAKEAWAY: A finite precision can cut off values during intermediate floating-point computations. For example, adding a sufficiently small value to a value greater than one can return the larger value unchanged. section 5.7.7

The word precision also appears in printf format specifications as the optional .PP component. That output-format component is distinct from the precision property of a type. section 8.3.4 section 5.2

How Modern C covers it

How deep it goes
Defines precision in bits and works through ranges, shifts, and a simplified floating-point representation.
Examples
Works through a 16-bit representation of 240, left shifts, and double-precision limit macros.
What you can do after
Evaluate/understand how type precision affects ranges, bit operations, and floating-point computations.
How it connects
Connects precision to unsigned integers, bit sets, shift operators, floating-point representation, and formatted output.

Also explained in

Compare how 10 books explain precision →

Related concepts

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