{
  "id": "fixed-point-arithmetic",
  "title": "Fixed-Point Arithmetic",
  "lang": "en",
  "source_lang": "en",
  "summary": "Fixed-point arithmetic represents numbers as integers with an implicit, predetermined scale, providing uniform absolute precision and explicit control over range, rounding, and overflow.",
  "category": "computer-science",
  "subcategory": "hardware",
  "type": "concept",
  "aliases": [
    "Fixed-point computation",
    "scaled-integer arithmetic"
  ],
  "generated_at": "2026-11-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/fixed-point-arithmetic/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/fixed-point-arithmetic/",
      "json": "https://aiwiki.page/zh/fixed-point-arithmetic.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "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."
    },
    {
      "heading": "Representation",
      "text": "A fixed-point value can be described as\n\n\\[x=I s,\\]\n\nwhere \\(I\\) is the stored integer and \\(s>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.\n\nFor binary fixed-point arithmetic, the common choice is\n\n\\[s=2^{-f},\\]\n\nwhere \\(f\\) is the number of fractional bits. Thus,\n\n\\[x=\\frac{I}{2^f}.\\]\n\nFor example, with \\(f=8\\), the integer \\(384\\) represents \\(384/256=1.5\\). The same stored integer represents a different number if interpreted using a different scale.\n\nA decimal fixed-point representation instead commonly uses \\(s=10^{-d}\\). With \\(d=2\\), the integer \\(12345\\) represents \\(123.45\\). The underlying integer may still be stored in binary: a decimal scale does not require a decimal hardware encoding.\n\nOrdinary integer arithmetic is the special case \\(s=1\\). More generally, a scale need not be a power of two or ten, although those choices simplify implementation and interpretation.\n\nRange and resolution\n\nFor an unsigned \\(w\\)-bit integer with \\(f\\) fractional bits, the representable range is\n\n\\[0\\leq x\\leq 2^{w-f}-2^{-f}.\\]\n\nFor a signed \\(w\\)-bit integer encoded in two’s complement, it is\n\n\\[-2^{w-f-1}\\leq x\\leq 2^{w-f-1}-2^{-f}.\\]\n\nAdjacent representable values are separated by\n\n\\[\\Delta=2^{-f}.\\]\n\nAt a fixed word length, increasing the number of fractional bits improves resolution but reduces range. The number of distinct bit patterns does not change.\n\nFor example, a signed 16-bit format with 15 fractional bits has range\n\n\\[-1\\leq x\\leq 1-2^{-15}.\\]\n\nIt represents \\(-1\\) exactly but cannot represent \\(+1\\). This asymmetry follows from the underlying two’s-complement integer range.\n\nQ notation\n\nBinary fixed-point formats are often described using Q notation. A notation such as Q\\(m.n\\) identifies integer and fractional portions, but conventions differ: some include the sign bit in \\(m\\), while others count it separately. Consequently, a Q-format label alone may not unambiguously specify the total storage width.\n\nAn unambiguous specification states:\n\n- total word length;\n- signed or unsigned interpretation;\n- scale or fractional-bit count;\n- rounding rule;\n- overflow behavior."
    },
    {
      "heading": "Arithmetic operations",
      "text": "Fixed-point operations combine integer arithmetic with explicit management of scales. A stored integer is meaningful only together with its scale.\n\nAddition and subtraction\n\nIf two operands have the same scale,\n\n\\[x=As,\\qquad y=Bs,\\]\n\nthen\n\n\\[x+y=(A+B)s.\\]\n\nThe stored integers can therefore be added directly, provided that the result fits in the destination representation.\n\nOperands 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.\n\nEven 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.\n\nMultiplication\n\nFor operands\n\n\\[x=A2^{-f_a},\\qquad y=B2^{-f_b},\\]\n\ntheir product is\n\n\\[xy=(AB)2^{-(f_a+f_b)}.\\]\n\nThe integer product naturally has the sum of the operands’ fractional-bit counts. To store it in a destination with \\(f_r\\) fractional bits, the required integer result is\n\n\\[R=\\operatorname{round}\\!\\left(AB\\,2^{f_r-f_a-f_b}\\right),\\]\n\nwhere \\(\\operatorname{round}\\) denotes the chosen rounding rule.\n\nIf both inputs and the output use \\(f\\) fractional bits, multiplication requires forming \\(AB\\) and then rescaling by \\(2^f\\). Two \\(w\\)-bit inputs can require a \\(2w\\)-bit intermediate product. Narrowing before rescaling may destroy significant information or cause integer overflow.\n\nDivision\n\nFor the same input conventions, a quotient stored with \\(f_r\\) fractional bits requires\n\n\\[R=\\operatorname{round}\\!\\left( \\frac{A\\,2^{f_r+f_b-f_a}}{B} \\right).\\]\n\nFor equal input and output scales, this becomes\n\n\\[R=\\operatorname{round}\\!\\left(\\frac{A2^f}{B}\\right).\\]\n\nScaling 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.\n\nAccumulation and other functions\n\nDot 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.\n\nIf \\(N\\) same-scale terms can all approach the maximum magnitude with the same sign, an accumulator may need approximately \\(\\lceil\\log_2 N\\rceil\\) additional magnitude bits. Tighter bounds are possible when input ranges and coefficients are known.\n\nSquare 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."
    },
    {
      "heading": "Rounding, quantization, and numerical error",
      "text": "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\n\n\\[|e|\\leq\\frac{\\Delta}{2},\\]\n\nprovided the rounded result remains within range.\n\nCommon 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.\n\nDiscarding 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.\n\nFixed-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.\n\nUnder an idealized model in which rounding error is uniformly distributed over an interval of width \\(\\Delta\\), its variance is\n\n\\[\\sigma_e^2=\\frac{\\Delta^2}{12}.\\]\n\nThis 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."
    },
    {
      "heading": "Overflow and saturation",
      "text": "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.\n\nCommon policies include:\n\n- Wraparound: retain only the available low-order bits, corresponding to modular arithmetic.\n- Saturation: clamp the result to the greatest or least representable value.\n- Checked arithmetic: signal an error or record an overflow condition.\n- Wider intermediates: postpone narrowing until the result has been bounded or rescaled.\n\nSaturation 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.\n\nA 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."
    },
    {
      "heading": "Comparison with floating-point arithmetic",
      "text": "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.\n\nProperty | Fixed-point | Floating-point\nScale | Predetermined for a format or operation | Varies through an encoded exponent\nSpacing | Uniform absolute spacing | Generally increases with magnitude\nRange at a given word length | Restricted by the selected scale | Usually much wider\nError analysis | Often organized around absolute error | Often organized around relative error\nImplementation | Integer operations plus scale management | Dedicated floating-point hardware or software\nExceptional values | Usually defined separately by the application | Standard formats commonly include infinities and NaNs\n\nFixed-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.\n\nNeither 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.\n\nThe IEEE 754 standard specifies widely used floating-point formats and operations; it is not a general specification for fixed-point arithmetic."
    },
    {
      "heading": "Applications",
      "text": "Digital signal processing and embedded control\n\nDigital 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.\n\nIn 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.\n\nFor 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.\n\nFinancial and decimal calculations\n\nAmounts 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.\n\nThe required scale depends on the application. Transaction totals, exchange rates, tax calculations, and intermediate accounting values may need different numbers of decimal places.\n\nMachine-learning inference\n\nNeural-network quantization often maps weights and activations to low-width integers for inference. Integer products are commonly accumulated at greater width before rescaling.\n\nA widely used affine representation is\n\n\\[x\\approx s(q-z),\\]\n\nwhere \\(q\\) is the stored integer, \\(s\\) is a scale, and \\(z\\) 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."
    },
    {
      "heading": "Development and implementation",
      "text": "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.\n\nImplementations 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.\n\nReliable 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:\n\n- deriving bounds for intermediate results;\n- reserving headroom and using wider accumulators;\n- keeping explicit records of scale changes;\n- testing negative values, rounding ties, and range boundaries;\n- comparing results against a higher-precision model;\n- applying formal verification where numerical guarantees are required.\n\nIncreasing 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."
    }
  ],
  "links": [
    "bit",
    "twos-complement",
    "integer-overflow",
    "algorithm",
    "polynomial",
    "real-number",
    "variance",
    "programming-language",
    "c-programming-language",
    "floating-point-arithmetic",
    "central-processing-unit",
    "ieee-seven-five-four",
    "neural-network-quantization",
    "neural-network-inference",
    "compiler",
    "formal-verification"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}