In computing, a fixed-point number representation is a real data type for a number that has a fixed number of digits after the decimal (or binary or hexadecimal) point. These numbers are useful for representing fractional values in native two's complement format if the executing processor has no floating point unit (FPU) or if fixed-point provides an improved performance. Most low cost embedded processors do not have an FPU. For example, a 16 bit signed fixed-point binary number with 4 bits after the decimal point yields 12 magnitude bits and 4 fractional bits. It can represent numbers between 2047.9375 and -2048. The asymmetry between upper and lower bounds is due to the two's complement notation. A 16 bit unsigned fixed-point binary number with 4 fractional bits ranges between 4095.9375 and 0. Fixed point numbers can represent fractional powers of two exactly, but, like floating point numbers, cannot exactly represent fractional powers of 10. If exact fractional powers of ten are desired, then Binary-coded decimal (BCD) format should be used. However, BCD does not make as efficient use of bits as two's complement notation, nor is it as computationally fast. For example, one-tenth (.1) and one-hundredth (.01) can be represented only approximately by two's complement fixed point or floating point representations, while they can be represented exactly in BCD representations.
Integer Fixed-point values aways exactly represent values up to the maximum/minimum determined by the number of magnitude bits. This is in contrast to floating-point representations, which include an automatically-managed exponent but cannot represent as many digits accurately (given the same number of bits in its representation).
A common use for fixed-point numbers is for storing monetary values, where the inexact values of floating-point numbers are often a liability. Fixed-point representations are also sometimes used if either the executing processor does not have any floating point unit (FPU) or if fixed-point provides an improved performance necessary for an application. Historically, fixed-point representations were the norm for decimal data types (for example, in PL/I or COBOL). The Ada programming language includes built-in support for both fixed-point and floating-point.
Very few computer languages include built-in support for fixed point values, because for most applications, floating-point representations are fast enough and accurate enough. Floating-point representations are more flexible than fixed-point representations, because they can handle a wider dynamic range. Floating-point representations are also slightly easier to use, because they do not require programmers to specify the number of digits after the decimal point.
However, if they are needed, fixed-point numbers can be implemented even in programming languages like C and C++ that do not include such support built-in.
Examples still in common use
- GnuCash is an application for tracking money. It is written in C and switched from a floating-point representation of money to a fixed-point implementation as of version 1.6. This change was made to avoid the potential rounding errors of floating-point representations.
- Tremor and Toast are software libraries that decode the Ogg Vorbis and GSM Full Rate audio formats respectively. These codecs use fixed-point arithmetic because many audio decoding hardware devices do not have an FPU (to save money) and audio decoding requires enough performance that a software implementation of floating-point on low-speed devices would not produce output in real time.
- All 3D graphics engines on Sony's original PlayStation and Nintendo's Game Boy Advance and Nintendo DS video game systems use fixed-point arithmetic for the same reason as Tremor and Toast: to gain throughput on an architecture without an FPU.
- Fractint represents numbers as Q3:29 fixed-point numbers[1].
- VisSim supports a fixed-point block set to allow simulation and automatic code generation of fixed-point operations. Both word size and and radix point can be specified on an operator basis.