3. Fixed-Point Numbers
Fractions without floating point
Integers are clean and fast, but they can only express whole numbers. The moment you need to represent a temperature of 98.6°F, a sound sample at 0.75 amplitude, or the price of something at $3.49, you need fractions.
The obvious solution — floating point — handles fractions brilliantly, but it comes at a cost. Floating-point hardware is complex, results can differ subtly between platforms, and the format carries unavoidable overhead: a sign bit, an exponent, and a significand, all encoded with special rules for infinity, NaN, and subnormal numbers. On a small microcontroller with no dedicated FPU, a single floating-point multiply might take hundreds of cycles.
Fixed-point arithmetic offers a simpler bargain: keep the fast integer hardware, but agree in advance where the decimal point sits.
The fixed-point idea in one sentence
Treat an ordinary integer as if it has been multiplied by a power of two — so the last f bits implicitly represent the fractional part. No special hardware required; only a convention.
The Implicit Radix Point
In a pure integer, every bit represents a power of two: 27, 26, …, 21, 20. In a fixed-point number we extend that sequence rightward past the radix point: 2−1 = 0.5, 2−2 = 0.25, and so on.
The crucial word is implicit. The number is still stored as a plain integer in memory — there is no special bit that marks the radix position. The position is a convention agreed upon at compile time, usually encoded in a type alias or a comment.
To recover the real value from a fixed-point integer, you simply divide by 2f, where f is the number of fractional bits. Because division by a power of two is a right-shift, this is a single CPU instruction.
Q Notation
Engineers need a compact way to document which format a variable uses. The most common convention is Q notation: Qi.f means i integer bits and f fractional bits.
Q8.8 — 16 bits total: 8 integer bits, 8 fractional bits.
Stored integer 256 → real value 256 / 28 = 256 / 256 = 1.0
Stored integer 384 → real value 384 / 256 = 1.5
Stored integer 1 → real value 1 / 256 ≈ 0.00390625 (smallest step)
Maximum value with 8 integer bits: 255 + 255/256 ≈ 255.996
Q16.16 — 32 bits total: 16 integer bits, 16 fractional bits.
Stored integer 65536 → real value 65536 / 216 = 1.0
Smallest step: 1 / 65536 ≈ 0.0000153
Maximum value: 65535 + 65535/65536 ≈ 65535.99998
Q16.16 is common in 3D graphics engines for sub-pixel precision and in audio DSP.
Some notations drop the integer part and write just Qf — for example, Q15 means a 16-bit value with 15 fractional bits and one integer bit (or sign bit in the signed variant), spanning roughly −1 to +1. This is the standard format for audio samples.
Fixed-Point Arithmetic
Addition and Subtraction
Two numbers in the same Q format can be added or subtracted with a plain integer add. The radix points are already aligned; no adjustment needed.
Q8.8 addition: add 1.5 and 0.75
1.5 → stored as 1.5 × 256 = 384
0.75 → stored as 0.75 × 256 = 192
384 + 192 = 576
576 / 256 = 2.25 ✓
Exactly one integer ADD instruction. No adjustment.
The only hazard is overflow: the result must fit in the integer type. If both operands are near the maximum, the sum overflows exactly as it would for plain integers.
Multiplication
Multiplication requires one extra step. When you multiply two Q8.8 numbers, the raw integer product has 16 fractional bits — double the expected count. You must right-shift by f to put the result back into Q8.8 format.
Q8.8 multiplication: multiply 1.5 by 2.0
1.5 → 384 | 2.0 → 512
Raw product: 384 × 512 = 196608
This represents 196608 / 216 = 3.0 — but stored with 16 fractional bits.
Right-shift by 8: 196608 >> 8 = 768
768 / 256 = 3.0 ✓
In C, you would typically widen to a larger integer type before multiplying to avoid overflow in the intermediate result:
typedef int16_t q8_8_t;
q8_8_t fp_mul(q8_8_t a, q8_8_t b) {
int32_t product = (int32_t)a * (int32_t)b;
return (q8_8_t)(product >> 8);
}
Division follows the reverse logic: left-shift by f before dividing, or the fractional bits vanish into the integer denominator.
Range vs. Precision Trade-off
The total number of bits stays the same. Moving the radix point to the right gives you more fractional bits — finer precision — but fewer integer bits, shrinking the maximum representable value. Moving it left does the reverse.
This trade-off must be decided at design time, which is why the developer must understand the expected magnitude of every quantity they work with.
Advantages
No special hardware required. Every device with integer arithmetic — from an 8-bit AVR to a 64-bit server — can run fixed-point code at full integer speed. No FPU needed.
Deterministic, bit-identical results. Integer arithmetic produces the same result on every conforming platform. Floating-point, by contrast, allows implementations to differ in rounding mode, intermediate precision, and FMA fusion, making cross-platform reproducibility surprisingly hard to guarantee. Fixed-point is a favourite in network protocols and game engines for this reason.
No NaN, no Infinity, no subnormal surprises. Floating-point has several special values that propagate silently and can corrupt results far from their origin. Fixed-point overflow wraps or saturates predictably.
Compact and cache-friendly. A Q8.8 array of a thousand audio samples takes 2 KB; the float32 equivalent takes 4 KB. Halving the memory footprint can be significant on a device with 32 KB of RAM.
Use Cases
Embedded systems (ARM Cortex-M0, M0+) — these cores have no hardware FPU. Audio codecs, sensor fusion, and motor control all use Q-format arithmetic. ARM's CMSIS-DSP library ships with a complete fixed-point math suite for exactly this reason.
Digital signal processing (DSP chips) — dedicated DSP architectures often have native support for Q15 and Q31 arithmetic, including saturating multiply-add instructions that accumulate products without overflowing.
Financial calculations — monetary values need exact decimal representation. In practice, financial software usually uses decimal fixed-point (scaled by powers of ten rather than two) or arbitrary-precision integers, but the principle is the same: store the value multiplied by a constant scale factor and track that factor explicitly.
Game physics and networking — deterministic simulation requires that every client computes the same result. Using Q16.16 fixed-point for positions and velocities guarantees lock-step replay and rollback consistency.
ARM NEON and fixed-point SIMD
ARM's NEON instruction set includes VQMUL and related instructions
that multiply Q15 values and automatically right-shift by 15, performing the
format correction in a single instruction. Eight Q15 multiplications in one
clock cycle — this is why fixed-point remains the first choice in
battery-powered audio and image processing.
Limitations
Limited range. The developer must choose the format before knowing the exact range of every variable. Choose too few integer bits and the program overflows silently; choose too many and precision is wasted.
Awkward API. Every multiplication needs an explicit shift. Different functions may use different Q formats, requiring conversion at boundaries. Code that mixes formats without discipline becomes error-prone fast.
Manual format tracking. There is no runtime type to carry the scale factor. If you pass a Q8.8 value to a function expecting Q16.16, the compiler will not warn you. The convention lives in comments and typedefs, not in the type system (though languages like Rust and C++ allow newtype wrappers to enforce it).
No gradual underflow. Values smaller than the step size are truncated to zero. Floating-point subnormal numbers handle very small values gracefully; fixed-point silently discards them.
Key Takeaways
- Fixed-point stores fractions as integers with an implicit scale factor of 2f. No special hardware, no special encoding — just a convention.
- Q notation (i.f) documents the format: Q8.8 means 8 integer bits and 8 fractional bits in 16 bits total.
- Addition is free — same as integer add. Multiplication needs a right-shift by f bits to correct the scale of the result.
- Range and precision are in direct tension. Moving the radix point trades one for the other; the developer must choose at design time.
- Advantages: no FPU needed, bit-identical across platforms, no NaN/Inf, compact memory.
- Drawbacks: limited range, manual format tracking, easy to silently mix incompatible formats.
Try It Yourself — Fixed-Point Explorer
Choose a Q format, enter a decimal value, and see exactly how fixed-point stores it — then try arithmetic to watch the shift correction in action.
Value Encoding
Arithmetic
Fixed-point solves the fraction problem elegantly within tight constraints — but the developer carries the burden of choosing the right format for every value, for all time. What if the hardware could carry that burden instead? What if the radix point could float to wherever the value needs it, automatically providing more precision for small numbers and more range for large ones?
That's exactly the idea behind IEEE 754 floating point — and it's where we go next.