Information representation and processing from computer system Chapter 2

Source: Internet
Author: User
Tags square root

1, the representation of integers most (all?) The number of machines with symbols is a complement indication.

2, integer operation. +-is +-+, bitwise plus minus, note signed and unsigned numeric overflow, */can be converted to shift and so on is also a bit truncation, you can first decimal calculation to 2 binary and then truncated.

3, is actually a kind of modulo operation, notice the word length causes truncation.

4, the expression of floating-point number:

Single Precision For example: 32-bit, 1-bit sign bit, 8-bit exponential bit (unsigned the actual value of the book is that he-127 namely the range is-127-128, the net is wrong-128-127), 23-bit mantissa, because the mantissa is 1 before the decimal point, so omitted, the calculation is added 1.

Infinity and other than NaN are the same as the number of floating point is ordered, from small to large in turn negative infinity, negative has a poor non-0 value, plus or minus 0 (then introduced), is a poor non-0 value and positive infinity. Any non-0 value other than NaN is divided by 0, and the result is infinite, while the symbol is determined by the symbol as the 0 of the divisor.

Recalling our introduction to Nan, when 0 divided by zero, the result is not infinite but NaN. The reason is not difficult to understand, when the divisor and dividend are close to 0 o'clock, its quotient may be any value, so the IEEE standard decided at this time to use NaN as a quotient more appropriate.

5, special values: We already know that the exponential field can actually be expressed in the range of the exponential value of 127 to 128 (including both ends). Where the value-127 (saved as full 0) and +128 (saved as full 1) are reserved for handling as special values.

6, non-normalized number

Let's examine a special case of floating-point numbers. Select two floating-point numbers with very small absolute values, as examples of single-precision binary floating-point numbers, such as 1.001x2-125 and 1.0001x2-125, which correspond to decimal 2.6448623x10-38 and 2.4979255x10-38 respectively. Obviously, they are all ordinary floating-point numbers (the exponent is-125, greater than the minimum allowable value-126; The mantissa is no problem), according to IEEE 754 can be saved separately as 00000001000100000000000000000000 (0x1100000) and 00000001000010000000000000000000 (0x1080000).

Now let's look at the difference between the two floating-point numbers. It is not difficult to conclude that the difference is 0.0001x2-125, which is expressed as the canonical floating-point number is 1.0x2-129. The problem is that its exponent is greater than the minimum allowable index value, so it cannot be saved as a canonical floating point number. Finally, it can only approximate 0 (Flush to Zero). This special situation means that the following inherently reliable code can also be problematic:

if (x! = y) {
z = 1/(x-y);
}

As with the two floating-point numbers we carefully selected, even if x is not equal to the difference between y,x and y, it is still possible that the absolute value is too small and approximately zero, resulting in a case divided by 0.

To address such issues, non-canonical (denormalized) floating-point numbers are introduced in the IEEE standard. Specifies that the mantissa does not have to be normalized when the index of the floating-point number is the minimum allowable exponent, that is, emin. For example, the difference in the above example can be expressed as a non-canonical floating-point number 0.001x2-126, where the exponent-126 equals emin. Note that the "no" is required, which means "yes". When the actual index of the floating-point number is emin, and the exponential field is also emin, the floating-point number is still canonical, that is, the storage implies a hidden trailing digit. To preserve non-canonical floating-point numbers, the IEEE standard uses a method similar to handling special value zeros, which is marked with the Special exponential field value emin-1, of course, at which point the mantissa field cannot be zero. Thus, the difference in the example can be saved as 00000000000100000000000000000000 (0x100000), with no implied trailing digits.

7. Signed 0

Because the IEEE standard floating-point number format, 1 of the decimal point to the left is hidden, and 0 obviously requires that the mantissa must be zero. Therefore, 0 can not be directly expressed in this format and only special treatment.

In fact, 0 is saved as the Mantissa field is all 0, the exponential field is emin-1 = 127, which means that the exponential field is also all 0. Given the role of the symbolic field, there are two zeros, +0 and 0. Unlike positive and negative infinity, which is ordered, the IEEE standard stipulates that plus or minus 0 is equal.

0 is a plus or minus point, and it's really easy to confuse. This is based on the numerical analysis of a variety of considerations, after the pros and cons of the resulting results. Signed 0 can avoid the loss of symbolic information in operations, especially those involving infinite operations. For example, if 0 is unsigned, the equation 1/(1/x) = x is no longer true when x =±∞. The reason is that if 0 is unsigned, the ratio of 1 and positive and negative infinity is the same 0, then the ratio of 1 to 0 is positive infinity, and the symbol is not. Solve this problem, unless infinity is not symbolic. But an infinite symbol expresses which side of the axis the overflow occurs on, and this information is clearly not allowed. 0 symbols also cause other problems, such as when X=y, the equation 1/x = 1/y when x and Y are +0 and 0 respectively, the two ends are positive infinity and negative infinity and no longer set. Of course, another way to solve this problem is to be as infinite as the rule that zero is ordered. However, if 0 is ordered, even simple judgments such as if (x==0) are uncertain because X may be ±0. Two harm take its light, 0 or disorderly good.

8, NaN

NaN is used to handle error conditions in calculations, such as 0.0 divided by 0.0 or the square root of a negative number. For single-precision floating-point numbers, NaN is expressed as an exponent of emax + 1 = 128 (exponential field is all 1), and the Mantissa field is not equal to zero floating-point number. The IEEE standard does not require a specific mantissa field, so NaN is not actually one, but a family.

9, Infinity

As with NaN, the exponential portion of the special Value Infinity (Infinity) is also emax + 1 = 128, but the infinite mantissa field must be zero . Infinity is used to express the overflow (Overflow) problem arising in the calculation. For example, when multiplying by two large numbers, although the two operands themselves can be saved as floating-point numbers, the result may be too large to be saved as a floating-point number and must be rounded. According to the IEEE standard, instead of rounding the results to the maximum number of floating-point numbers that can be saved (because the numbers may be too far from the actual result to be meaningless), they are rounded to infinity. This is true for negative results, except that rounding is negative infinity, which means that the symbol field is 1 infinity.

10, the mantissa domain is not all 0 emin-1 = 127, the exponential field is all 0, does not exist, because can be used non-canonical representation. I understand that.

11. Calculation of floating-point numbers: This operation is usually accompanied by an approximation or rounding that cannot be accurately represented.

+-: Two floating point arithmetic rules for addition and subtraction are set Ex less than equals Ey, then X±y = (mx*2^ (ex-ey) ±my) *2^ey, rounding processing

http://blog.csdn.net/b2b160/article/details/4492519

Http://www.cnblogs.com/kingwolfofsky/archive/2011/07/21/2112299.html

Http://baike.baidu.com/view/339796.htm

Information representation and processing from computer system Chapter 2

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.