liveBook · Manning

Fixed-point arithmetic

As explained in Quantization and Fast Inference

Fixed-point arithmetic performs calculations on values encoded with a fixed scaling factor.

Fixed-point arithmetic represents values as integers on a fixed grid. For a chosen bit width, allocating more bits to range leaves fewer for precision. section 2.6 section 2.1

Figure 2.1 The Q3.4 fixed-point format divides 8 bits into a sign bit, 3 integer bits, and 4 fractional bits. Here, the bit pattern 0 001 1000 encodes +1.5 — the integer bits 001 contribute 1, and the leading fractional bit 1000 contributes 2-¹ = 0.5.

The Q3.4 diagram shows how an 8-bit pattern encodes a value and divides bits between integer and fractional parts. section 2.1

A fixed-point implementation must account for:

  • Quantization maps values to grid points; rounding error is bounded by half a step, while clipping values outside the grid can cause larger distortion. section 2.6
  • Multiplication increases the number of fractional bits, so the product must be shifted back; rounding before the shift avoids the systematic downward error of truncation. section 2.1
  • Overflow can wrap in two's-complement arithmetic or be constrained by saturation; range limits apply to both inputs and accumulated results. section 2.6
  • For quantized tensors, scale and zero-point map integer storage to real values; symmetric weights and asymmetric activations pair different grid choices with their distributions. section 2.6

Q3.4 arithmetic

In Q3.4, 1.5 and 0.5 are stored as raw integers 24 and 8. Their product is shifted back to produce 0.75; storing 10.0 or adding 5.0 to 5.0 saturates at 7.9375. section 2.1

How Quantization and Fast Inference covers it

How deep it goes
Works through Q-format encoding, multiplication rescaling, rounding, overflow, and tensor scale choices.
Examples
Uses Q3.4 multiplication, saturation of 10.0, and overflow from adding two 5.0 values.
What you can do after
Build a Q3.4 simulator that exposes raw values and models multiplication, rounding, and saturation.
How it connects
Connects Q-format representation to two's complement, quantization, affine quantization, and calibration.

Related concepts

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