Fixed-point arithmetic: Difference between revisions

Content deleted Content added
m dablink
No edit summary
Line 3:
{{dablink|This article is about a form of limited-precision arithmetic in computing. For the fixed points of a mathematical function, see [[fixed point (mathematics)]].}}
 
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 fixed-point number with 4 digits after the decimal point could be used to store numbers such as 1.3467, 281243.3234 and 0.1000, but would round 1.0301789 to 1.0302 and 0.0000654 to 0.0001.
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.
 
Fixed-point can exactly represent decimal fractions while still employing the base 2 arithmetic that is
efficient in most of today's computers.
Most floating point representations in computers use base 2 values, which cannot exactly represent
most fractions that are easily represented in base 10.
For example, one-tenth (.1) and one-hundredth (.01) can be represented only approximately
by base-2two's complement fixed point or floating point representations, while they can be represented exactly in fixed-pointBCD representations — one simply stores the data values multiplied by the appropriate power of 10.
 
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|floating-point]] representations, which include
As long as the numeric value uses only the number of digits specified after the
decimal point, fixed-point values
can exactly represent all values up to its maximum value (determined by the number of bits
in its representation).
This is in contrast to [[floating point|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).