Computer decimals.

Source: Internet
Author: User

In general writing, the decimal point is marked ". "To represent, but in a computer, any information can only be expressed in 0 or 1 digital. If the decimal point in a computer is expressed in digital, it is difficult to distinguish it from binary digits, therefore, the decimal point in the computer cannot be expressed with a mark. How can we determine the decimal point in the computer?

In order to determine the decimal point location, there are two methods to represent the number: the fixed point representation and the floating point representation.

The so-called fixed point and floating point indicate whether the decimal point of a number is fixed or floating.

(1) fixed point representation

The so-called fixed-point notation means that the positions of the decimal points in the computer are invariably set by humans. In this way, the decimal point does not need to be represented by a mark. Generally, the decimal point can be fixed after any digit, but the following two forms are commonly used: ① fixed point pure decimal point: the specified decimal point is fixed after the symbol, for example: Apparently, the number of points allows the computer to process only pure integers or decimals, which limits the scope of data processing by the computer. To enable the computer to process any number, we must first multiply the number involved in the operation by a "proportional factor", convert it to a pure decimal or a pure integer, and then perform the operation. Returns the proportional factor of the operation result to the actual value. The proportional factor should be appropriate so that the number involved in the calculation, the intermediate result of the calculation, and the final result are within the range of values that can be expressed by the number of points.

(2) floating point representation

In the floating point representation, the decimal point is floating. To allow the decimal point to float freely, a floating point number consists of two parts: the ending part and the order part. The floating point number in the machine is represented as follows: the ending part indicates all valid digits of the floating point number, which is a pure decimal with a sign; the Order section specifies the displacement p between the actual decimal point location of the floating point and the ending number (Fixed Point pure decimal point. The displacement P (Order) is a pure decimal number with a sign. When the order is + P, the decimal point moves P to the right. When the order is-P, the decimal point and the left move p. Therefore, the decimal point of a floating point number fluctuates freely with the symbol and size of P. From the above we can see that a floating point number is composed of two fixed points. A fixed point can also be seen as a special case of floating point numbers. That is, when the order of the floating point is zero (indicating that the actual decimal point of the number is the same as the agreed position of the decimal point), the floating point number only has the ending part. Similarly, the fixed point notation is the basis of the floating point notation, and the floating point notation is the application of the fixed point notation. In theory, the relationship between them is as follows.

We know that any binary number can always be expressed as the product of a pure decimal (or pure integer) and an integer power of 2. For example, any binary number N can be written:

N = S x 2 ^ P

In formula, S is called the ending number of N; P is called the order number of n, where P and S are expressed in binary. The ending number S represents all valid numbers of the number N. Obviously, the more digits s use, the higher the accuracy of the value represented by the number n. The Order p specifies the decimal point of the number N. Obviously, the larger the number P uses, the larger the value range represented by the number n.

If p = 0, n = S x 20 = S. If the ending number S is a pure decimal number, n is a fixed point decimal number.

For example, if p = 0 and S are pure integers, n is a fixed integer.

Assume that p = any integer. In this case, the number N must be expressed by the ending number s and the order p, that is, the number N is a floating point number.

Obviously, the range of a floating point is much larger than that of a fixed point. If the order digit of a floating point number is m + 1 and the ending digit is n + 1, the floating point value range is: although a floating point number has the outstanding advantage of a large value range, floating point operations are complex. When a computer performs a floating point operation, it needs to perform two fixed point Operations respectively.

For example, set two floating point numbers:

N1 = 2 ^ P1 × S1

N2 = 2 ^ P2 × S2

For example, if P1 is equal to P2, the two numbers cannot be directly added or subtracted. First, the decimal point (that is, the level of order) must be aligned before the addition and subtraction operations between the ending numbers can be performed. In order, the order is aligned with the order, that is, the decimal point of the Order is shifted to the left. In the computer, the number is shifted to the right, shifted to 1, and the order code is added to 1, the order code is the same until the two numbers are added or subtracted.

The multiplication and division of floating point numbers. The order code and the ending number must be calculated separately.

To prevent the loss of valid numbers in the computer operation process and improve the operation accuracy, binary floating point normalization is generally used. The so-called floating point normalization means that the absolute value of the ending number S is smaller than 1 and greater than or equal to 1/2, that is, one digit after the decimal point must be "1 ". For example, n = 2 + 100 × 0. 1011101 is a floating point normalized number. Due to the complexity of floating-point calculation, in addition to the tail operation components, the generator also has the order code operation components, and the control components are also correspondingly complicated. Therefore, the increase in the number of floating-point devices leads to a high cost.

In the computer, whether the floating or fixed point system is used must be designed according to the requirements. At present, General minicomputers and minicomputers mostly adopt fixed-point systems, while mainframes, giant computers, and high-end minicomputers mostly adopt floating point systems.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.