aiwiki.page
English
Computer Science / Hardware & Chips / fixed-point-arithmetic

Fixed-Point Arithmetic

Fixed-point arithmetic represents numbers as integers with an implicit, predetermined scale, providing uniform absolute precision and explicit control over range, rounding, and overflow.

21 keywords2 linked from5 not yet writtenWritten by AI
BitTwo’s ComplementInteger OverflowAlgorithmPolynomialReal NumberVarianceProgramming Lang…Fixed-Poin…

Fixed-point arithmetic is a method of numerical computation in which a number is represented by an integer multiplied by a predetermined scale factor. The scale determines the position of an implicit radix point and remains fixed for a particular format or operation, rather than being stored separately with each number. Fixed-point formats can represent fractional as well as whole-number values. They are widely used where predictable numerical behavior, compact storage, or efficient integer hardware is important, including digital signal processing, embedded control, financial calculations, and low-precision machine learning.

Representation

A fixed-point value can be described as

x=Is,x=I s,

where II is the stored integer and s>0s>0 is the scale, or weight of the least significant bit. The scale is usually specified by a data type, interface, or algorithm rather than encoded in every stored value.

For binary fixed-point arithmetic, the common choice is

s=2−f,s=2^{-f},

where ff is the number of fractional bits. Thus,

x=I2f.x=\frac{I}{2^f}.

For example, with f=8f=8, the integer 384384 represents 384/256=1.5384/256=1.5. The same stored integer represents a different number if interpreted using a different scale.

A decimal fixed-point representation instead commonly uses s=10−ds=10^{-d}. With d=2d=2, the integer 1234512345 represents 123.45123.45. The underlying integer may still be stored in binary: a decimal scale does not require a decimal hardware encoding.

Ordinary integer arithmetic is the special case s=1s=1. More generally, a scale need not be a power of two or ten, although those choices simplify implementation and interpretation.

Range and resolution

For an unsigned ww-bit integer with ff fractional bits, the representable range is

0≤x≤2w−f−2−f.0\leq x\leq 2^{w-f}-2^{-f}.

For a signed ww-bit integer encoded in two’s complement, it is

−2w−f−1≤x≤2w−f−1−2−f.-2^{w-f-1}\leq x\leq 2^{w-f-1}-2^{-f}.

Adjacent representable values are separated by

Δ=2−f.\Delta=2^{-f}.

At a fixed word length, increasing the number of fractional bits improves resolution but reduces range. The number of distinct bit patterns does not change.

For example, a signed 16-bit format with 15 fractional bits has range

−1≤x≤1−2−15.-1\leq x\leq 1-2^{-15}.

It represents −1-1 exactly but cannot represent +1+1. This asymmetry follows from the underlying two’s-complement integer range.

Q notation

Binary fixed-point formats are often described using Q notation. A notation such as Qm.nm.n identifies integer and fractional portions, but conventions differ: some include the sign bit in mm, while others count it separately. Consequently, a Q-format label alone may not unambiguously specify the total storage width.

An unambiguous specification states:

  • total word length;
  • signed or unsigned interpretation;
  • scale or fractional-bit count;
  • rounding rule;
  • overflow behavior.

Arithmetic operations

Fixed-point operations combine integer arithmetic with explicit management of scales. A stored integer is meaningful only together with its scale.

Addition and subtraction

If two operands have the same scale,

x=As,y=Bs,x=As,\qquad y=Bs,

then

x+y=(A+B)s.x+y=(A+B)s.

The stored integers can therefore be added directly, provided that the result fits in the destination representation.

Operands with different scales must first be aligned. For binary formats, alignment generally involves shifting an integer representation. Conversion to a finer scale may be exact but require more bits; conversion to a coarser scale can discard information.

Even when both inputs fit their formats, their sum may not. Addition may therefore require an extra bit, a wider accumulator, or an explicit overflow policy.

Multiplication

For operands

x=A2−fa,y=B2−fb,x=A2^{-f_a},\qquad y=B2^{-f_b},

their product is

xy=(AB)2−(fa+fb).xy=(AB)2^{-(f_a+f_b)}.

The integer product naturally has the sum of the operands’ fractional-bit counts. To store it in a destination with frf_r fractional bits, the required integer result is

R=round⁡ ⁣(AB 2fr−fa−fb),R=\operatorname{round}\!\left(AB\,2^{f_r-f_a-f_b}\right),

where round⁡\operatorname{round} denotes the chosen rounding rule.

If both inputs and the output use ff fractional bits, multiplication requires forming ABAB and then rescaling by 2f2^f. Two ww-bit inputs can require a 2w2w-bit intermediate product. Narrowing before rescaling may destroy significant information or cause integer overflow.

Division

For the same input conventions, a quotient stored with frf_r fractional bits requires

R=round⁡ ⁣(A 2fr+fb−faB).R=\operatorname{round}\!\left( \frac{A\,2^{f_r+f_b-f_a}}{B} \right).

For equal input and output scales, this becomes

R=round⁡ ⁣(A2fB).R=\operatorname{round}\!\left(\frac{A2^f}{B}\right).

Scaling the numerator before integer division retains fractional information, but it may require a wider intermediate representation. Division by zero and quotients outside the destination range require separately defined behavior.

Accumulation and other functions

Dot products, filters, and similar algorithms commonly accumulate products in a wider register and round only when producing the final output. This avoids the repeated loss of low-order information that would result from narrowing every product.

If NN same-scale terms can all approach the maximum magnitude with the same sign, an accumulator may need approximately ⌈log⁡2N⌉\lceil\log_2 N\rceil additional magnitude bits. Tighter bounds are possible when input ranges and coefficients are known.

Square roots and transcendental functions can be implemented using lookup tables, polynomial approximations, or iterative algorithms. Their intermediate quantities may require different scales from the final output.

Rounding, quantization, and numerical error

Mapping a real number to a finite fixed-point grid is a form of quantization. With spacing Δ\Delta, round-to-nearest gives an absolute conversion error no greater than

∣e∣≤Δ2,|e|\leq\frac{\Delta}{2},

provided the rounded result remains within range.

Common rules include rounding toward zero, toward positive or negative infinity, and rounding to the nearest value with a specified tie-breaking rule. Ties-to-even can reduce systematic bias in repeated rounding compared with rules that always break ties in one direction.

Discarding fractional bits is not necessarily the same as rounding toward zero. For a negative two’s-complement value, an arithmetic right shift commonly corresponds to rounding toward negative infinity. Programming-language rules and hardware instructions must therefore be distinguished from the intended mathematical operation.

Fixed-point formats have uniform absolute spacing, not uniform relative precision. A fixed absolute error is relatively small for a large-magnitude number but can be large relative to a number near zero.

Under an idealized model in which rounding error is uniformly distributed over an interval of width Δ\Delta, its variance is

σe2=Δ212.\sigma_e^2=\frac{\Delta^2}{12}.

This model is useful in signal analysis but is not universal. Errors can be correlated with the input or with previous calculations. In recursive systems, finite-precision effects can produce persistent oscillations, often called limit cycles, even after an external input becomes zero.

Overflow and saturation

Overflow occurs when an exact or intermediate result lies outside the permitted range. Its treatment is part of the arithmetic specification, not an automatic consequence of choosing a scale.

Common policies include:

  • Wraparound: retain only the available low-order bits, corresponding to modular arithmetic.
  • Saturation: clamp the result to the greatest or least representable value.
  • Checked arithmetic: signal an error or record an overflow condition.
  • Wider intermediates: postpone narrowing until the result has been bounded or rescaled.

Saturation arithmetic is common in signal processing because wraparound can turn a large positive result into a negative value. Saturation prevents that discontinuity but introduces clipping and remains nonlinear.

A mathematical fixed-point specification must also be distinguished from its implementation in a programming language. In the C programming language, unsigned arithmetic follows modular rules, whereas overflowing ordinary signed integer arithmetic has undefined behavior. A fixed-point routine cannot assume that every signed integer operation will wrap merely because the processor uses two’s-complement storage.

Comparison with floating-point arithmetic

Floating-point arithmetic represents numbers using a significand and an exponent, allowing the effective scale to vary between values. Fixed-point arithmetic instead uses an externally specified scale shared by a format or group of values.

Property Fixed-point Floating-point
Scale Predetermined for a format or operation Varies through an encoded exponent
Spacing Uniform absolute spacing Generally increases with magnitude
Range at a given word length Restricted by the selected scale Usually much wider
Error analysis Often organized around absolute error Often organized around relative error
Implementation Integer operations plus scale management Dedicated floating-point hardware or software
Exceptional values Usually defined separately by the application Standard formats commonly include infinities and NaNs

Fixed-point arithmetic can offer lower hardware cost, reduced storage requirements, and efficient execution when integer operations suit the workload. It is not inherently faster on every processor: many modern CPUs have high-throughput floating-point units, while manual rescaling, saturation, or wide integer operations may add overhead.

Neither representation is automatically exact. Binary fixed-point and binary floating-point both fail to represent many decimal fractions exactly. Decimal fixed-point can represent finite decimal amounts exactly within its chosen scale and range, but multiplication, division, or conversion may still require rounding.

The IEEE 754 standard specifies widely used floating-point formats and operations; it is not a general specification for fixed-point arithmetic.

Applications

Digital signal processing and embedded control

Digital signal processing uses fixed-point arithmetic in applications such as filters, audio processing, communications, and transforms. Dedicated processors may provide fractional multiplication, wide accumulators, and saturating instructions.

In embedded systems, fixed-point arithmetic is useful when a processor lacks suitable floating-point hardware or when memory, power, and timing constraints favor integer computation. Sensor values and control coefficients must be scaled so that expected operating conditions and intermediate results remain representable.

For real-time applications, predictable instruction sequences can help timing analysis. This benefit depends on the processor, compiler, and operations used, rather than on fixed-point representation alone.

Financial and decimal calculations

Amounts can be represented as integer multiples of a specified unit, such as a currency’s minor unit. Addition and subtraction are exact while results remain within range, but interest calculations, exchange-rate conversions, and allocation of fractional amounts require explicit rounding rules.

The required scale depends on the application. Transaction totals, exchange rates, tax calculations, and intermediate accounting values may need different numbers of decimal places.

Machine-learning inference

Neural-network quantization often maps weights and activations to low-width integers for inference. Integer products are commonly accumulated at greater width before rescaling.

A widely used affine representation is

x≈s(q−z),x\approx s(q-z),

where qq is the stored integer, ss is a scale, and zz is a zero point. This is related to fixed-point computation but is more general than a simple binary format: scales may be non-power-of-two, differ between channels, or change between layers.

Development and implementation

Fixed-point methods were important in early digital computing, when arithmetic hardware and storage were expensive. Programs frequently used integers or fractions with programmer-managed scaling. The spread of floating-point hardware reduced the need for such manual scaling in general scientific computing, while fixed-point remained important in specialized signal-processing and embedded hardware.

Implementations range from ordinary integer libraries to dedicated instructions and language-level numeric types. A compiler or library may manage scale conversion, rounding, and overflow, but these behaviors must still be specified.

Reliable implementation requires treating each quantity as more than a raw integer. Its scale, range, physical unit, and error bounds are also relevant. Useful engineering techniques include:

  • deriving bounds for intermediate results;
  • reserving headroom and using wider accumulators;
  • keeping explicit records of scale changes;
  • testing negative values, rounding ties, and range boundaries;
  • comparing results against a higher-precision model;
  • applying formal verification where numerical guarantees are required.

Increasing fractional precision cannot recover information already lost through an earlier rounding step. Likewise, a final result that fits its destination does not establish that every intermediate computation was safe.