Content deleted Content added
mNo edit summary |
mNo edit summary |
||
Line 10:
where ''m'' is bits of magnitude and ''f'' is bits of fraction.
For example, a 16 bit signed fixed-point binary number with 4 bits after the radix 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 [[
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 are aways exactly represented so long as they fit within the range determined by the magnitude bits. This is in contrast to [[floating point|floating-point]] representations, which have separate exponent and value fields which can allow specification of integer values larger than the number of bits in the value field, causing the represented value to lose precision.
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. 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 easier 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.
However, if they are needed, fixed-point numbers can be implemented even in programming languages like [[C programming language|C]] and [[C++]] that do not include such support built-in.
==Examples still in common use==
|