Fixed-point arithmetic

A fixed-point number is a number consisting of a fixed number of digits. The position of the comma is predefined, hence the name.

The basic idea behind this is the information technology representation of a section of the rational numbers. This figure is limited to a large data types, typically integer of different bit widths, requires a fixed number of digits for decimal - such as the fractional part. Usually, by definition, the first digits of the decimal point and the remaining decimal places. In computer science have decimal as binary fixed-point numbers a great practical significance.

  • 3.1 Application Examples

Advantages and disadvantages compared to a floating point number

Performance consideration

Due to the fixed position of the decimal point computational effort falls off compared to the calculation with floating point numbers. If you select a binary fixed-point representation in a computer program, also necessary for the conversion and correction multiplications and divisions can be replaced with fast shift operations. An example of an application that was designed specifically for computational cost reasons, with fixed-point arithmetic, for example, Fractint, a fractal generator. Since the mid- 1990s processors have dedicated Gleitkommarechenwerke which lead to the calculation of fractals is faster than the integers with floating point numbers.

Precision and dynamics

Due to the exact representation of the value range of a fixed-point number is smaller than the respective value range of a floating point number of the same ( bit ) length. This, however, the accuracy of the representation of a number in the entire range of values ​​is saved in floating-point numbers is not always (e.g. by absorption ). An example of an application that uses fixed-point numbers because of the necessary represent precisely, GnuCash is.

Representation Example: Binary fixed -point number

All the binary fixed-point numbers with a length with the decimal:

Note that each of the four binary pattern is listed for each of three different numbers, depending on which position the point is set. As the number of digits before already is fixed by definition, it is unnecessary to write the usual comma or store, ie the representation is always that of the column " binary pattern ".

Calculating with fixed-point numbers

In the calculation with fixed-point numbers, the binary patterns are basically processed as in the calculation with whole numbers. Fixed point arithmetic may thus be performed by any digital processor, the support arithmetic operations on integers. Nevertheless, some rules must be observed that relate to the position of the comma before and after the arithmetic operation:

  • In addition and subtraction the position of the decimal point for all operands must be the same. If this is not the case, the operands must be adjusted accordingly by shift operations. The decimal point position of the result then corresponds to the decimal point position of the operands.
  • For multiplication, the number of digits before the result of the sum of the numbers of digits before all operands; also corresponds to the number of decimal places in the result of the sum of the numbers of decimal places of all operands.
  • A division or multiplication by a power corresponds to a bit shift operation of the binary pattern to the right or left for positions at a constant point position. Alternatively, the operation can be thought of as an imaginary shift of the comma.

Application Examples

The following examples assume a fixed-point decimal representation, in which two decimal places are provided. This is expressed by a factor of 100, to which the initial values ​​are multiplied to obtain the fixed-point representation.

Decimal:

Binary:

Result would be in accordance with the 8- bit fixed -point format with 4 decimal places:

Incorrect display of the decimal point position, therefore, the shift operation is necessary:

Result would be in accordance with the 8- bit fixed -point format with 4 decimal places:

The result after the correction now corresponds to the expected result.

Problems

In the representation of a real number, it may be some problems. The following are the fixed-point number has (based on the representation in a computer ) and a length of digits before and after. The digits stock is - ie a binary fixed -point number of the length of a byte with the same number of digits before and after. The subscript refers to the representation of the number: a real number in the usual decimal notation, and for such a fixed-point number.

As you can see, that can only fixed-point numbers between and are shown ( at a resolution of ) with 8 bits and 4 and decimal places. This small display area is also the main disadvantage compared to floating point numbers.

Continue to emerge as well as in floating-point rounding errors when converting the decimal, real numbers in a binary fixed-point representation. can be represented as opposed to exact. however, can not be represented as a sum of powers of two no matter how many decimal places. To circumvent these problems, but a fixed point decimal representation can be used when needed.

332482
de