Fixed-point arithmetic: Difference between revisions

Content deleted Content added
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 hexadecimalradix) point. TheseThe numbersbits to the left of the radix point are usefulmagnitude forbits representingthat represent integer values, the bits to the right of the radix point represent fractional values. in nativeEach [[two'sfractional complement]]bit formatrepresents an inverse power of 2. ifThus the executingfirst processorfractional hasbit nois [[floating1/2, point]]the unitsecond (FPU)is or1/4, ifthe fixed-pointthird providesis an1/8 and so on.
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.
Line 9 ⟶ 10:
by two's complement fixed point or floating point representations, while they can be represented exactly in BCD representations.
 
Integer Fixedfixed-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 includehave separate exponent and value fields which can allow specification of integer values larger than the number of bits in the value field.
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 BCD numbers is for storing monetary values, where the inexact values
of floating-point numbers are often a liability.
FixedHistorically, fixed-point representations arewere alsothe sometimesnorm usedfor ifdecimal eitherdata thetypes executing(for processorexample, doesin not[[PL/I]] have anyor [[floating pointCOBOL]] unit (FPU) or if fixed-point provides an.
The [[Ada programming language]] includes built-in support for both fixed-point and floating-point.
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 flexibleeasier than fixed-point representations, because they can handle a wider dynamic range and do not require programmers to specify the number of digits after the radix point.
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