ArticleslgStudy

computer science

Fixed-point arithmetic

Fixed-point arithmetic is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Fixed-point arithmetic rather than just read about it. In short: In computing, fixed-point is a method of representing fractional (non-integer) numbers by storing a fixed number of digits of their fractional part. Dollar amounts, for example, are often stored with exactly two fractional digits, representing the cents (1/100 of a dollar).

Key takeaways

  • Fixed-point arithmetic belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Fixed-point arithmetic to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Fixed-point arithmetic from memory before moving on to harder problems.

Reference excerpt

In computing, fixed-point is a method of representing fractional (non-integer) numbers by storing a fixed number of digits of their fractional part. Dollar amounts, for example, are often stored with exactly two fractional digits, representing the cents (1/100 of a dollar). More generally, the term may refer to representing fractional values as integer multiples of some fixed small unit, e.g., a fractional amount of hours as an integer multiple of ten-minute intervals. Fixed-point number representation is often contrasted to the more complicated and computationally demanding floating-point representation. In the fixed-point representation, the fraction is often expressed in the same number base as the integer part, but using negative powers of the base b. The most common variants are decimal (base 10) and binary (base 2). The latter is commonly known also as binary scaling. Thus, if n fraction digits are stored, the value will always be an integer multiple of b−n. Fixed-point representation can also be used to omit the low-order digits of integer values, for instance, when representing large dollar values as multiples of $1000 ($1K). When decimal fixed-point numbers are displayed for human reading, the fraction digits are usually separated from those of the integer part by a radix character (usually "." in English, but "," or some other symbol in many other languages). Internally, however, there is no separation, and the distinction between the two groups of digits is defined only by the programs that handle such numbers. Fixed-point representation was the norm in mechanical calculators. Since most modern processors have a fast floating-point unit (FPU), fixed-point representations in processor-based implementations are now used only in special situations, such as in low-cost embedded microprocessors and microcontrollers; in applications that demand high speed or low power consumption or small chip area, like image, video, and digital signal processing; or when their use is more natural for the problem. Examples of the latter are accounting of dollar amounts, when fractions of cents must be rounded to whole cents in strictly prescribed ways; and the evaluation of functions by table lookup, or any application where rational numbers need to be represented without rounding errors (which fixed-point does but floating-point cannot). Fixed-point representation is still the norm for field-programmable gate array (FPGA) implementations, as floating-point support in an FPGA requires significantly more resources than fixed-point support.

Representation

A fixed-point representation of a fractional number is essentially an integer that is to be implicitly multiplied by a fixed scaling factor. For example, the value 1.23 can be stored in a variable as the integer value 123 with an implicit scaling factor of 1/100. This representation allows standard integer arithmetic logic units to perform rational number calculations. Negative values are usually represented in binary fixed-point formats as a signed integer in two's complement representation with an implicit scaling factor as above. The sign of the value will always be indicated by the most significant bit (1 = negative, 0 = non-negative), even if the number of fraction bits is greater than or equal to the total number of bits. For example, the 8-bit signed binary integer (11110101)2 = −11, taken with −3, +5, and +12 implied fraction bits, would represent the values −11/2−3 = −88, −11/25 = −0.34375, and −11/212 = −0.002685546875, respectively. Alternatively, negative values can be represented by an integer in the sign-magnitude format, in which case the sign is never included in the number of implied fraction bits. This variant is more commonly used in decimal fixed-point arithmetic. Thus the signed 5-digit decimal integer (−00025)10, taken with −3, +5, and +12 implied decimal fraction digits, would represent the values −25/10−3 = −25000, −25/105 = −0.00025, and −25/1012 = −0.000000000025, respectively. A program will usually assume that all fixed-point values that will be stored into a given variable, or will be produced by a given instruction, will have the same scaling factor. This parameter can usually be chosen by the programmer depending on the precision needed and the range of values to be stored. The scaling factor of a variable or formula may not appear explicitly in the program. Coding best practices then requires that it be provided in the documentation, at least as a comment in the source code.

Choice of scaling factors For greater efficiency, scaling factors are often chosen to be powers (positive or negative) of the base b used to represent the integers internally. However, often the best scaling factor is dictated by the application. Thus, one often uses scaling factors that are powers of 10 (e.g., 1/100 for dollar values) for human convenience, even when the integers are represented internally in binary. Decimal scaling factors also mesh well with the metric (SI) system, since the choice of the fixed-point scaling factor is often equivalent to the choice of a unit of measure (like centimeter or micron in relation to meter). However, other scaling factors may be used occasionally, e.g., a fractional amount of hours may be represented as an integer number of seconds; that is, as a fixed-point number with a scale factor of 1/3600. Even with the most careful rounding, fixed-point values represented with a scaling factor S may have an error of up to ±0.5 × S in the stored integer value. Therefore, smaller scaling factors generally produce more accurate results. On the other hand, a smaller scaling factor means a smaller range of the values that can be stored in a given program variable. The maximum fixed-point value that can be stored into a variable is the largest integer value that can be stored into it, multiplied by the scaling factor, and similarly for the minimum value. For example, the table below gives the implied scaling factor S, the minimum and maximum representable values Vmin and Vmax, and the accuracy δ = S/2 of values that could be represented in 16-bit signed binary fixed point format, depending on the number f of implied fraction bits.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Fixed-point arithmetic

Start with the simplest possible case. Write down what Fixed-point arithmetic claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Fixed-point arithmetic before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Fixed-point arithmetic ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Fixed-point arithmetic

In research
Fixed-point arithmetic appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Fixed-point arithmetic in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Fixed-point arithmetic is common in secondary-school and first-year university syllabi. It links to neighbouring topics Binary arithmetic, Computer arithmetic, Data types, so understanding it makes those chapters shorter.
In everyday life
Look for Fixed-point arithmetic outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Fixed-point arithmetic” →

How to study Fixed-point arithmetic in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Fixed-point arithmetic means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Fixed-point arithmetic out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Fixed-point arithmetic in simple terms?

In computing, fixed-point is a method of representing fractional (non-integer) numbers by storing a fixed number of digits of their fractional part. Dollar amounts, for example, are often stored with exactly two fractional digits, representing the cents (1/100 of a dollar).

Why does Fixed-point arithmetic matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Fixed-point arithmetic?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Fixed-point arithmetic.

Tags

  • Binary arithmetic
  • Computer arithmetic
  • Data types
  • Primitive types

Keep exploring