Fixed-point arithmetic (source code)

= Fixed-point arithmetic
{title2=$x=k\Delta$}

<Fixed-point arithmetic> represents values as <integer multiples> $k\Delta$ of a fixed scale $\Delta$. Integer operations on $k$, followed by the required rescaling and <rounding>, implement arithmetic on these values. Unlike <floating-point arithmetic>, the spacing is constant throughout the representable range.

For $\Delta=2^{-8}$, the stored integer $384$ represents $1.5$. Multiplying two encoded values $k\Delta$ and $\ell\Delta$ gives $k\ell\Delta^2$, so returning to the original scale requires dividing the integer product by $1/\Delta$ with a stated rounding rule. Fixed spacing makes resolution predictable, but the chosen integer width <limits> range and can cause <integer overflow>.