Representation and processing of information (4)

Source: Internet
Author: User

2.4 Floating point

Floating-point numbers make a lot of sense to design very large figures and very close to 0 numbers, but the first floating-point number doesn't have a single standard, and then the IEEE 754 standard comes up, and the standard is still in use, and the next thing we want is the floating-point format in the IEEE standard ... Because this part of my freshman year when I learned some, so may be more brief ...

2.41 binary Decimals

Of course, you will find that we have no way of representing a number of decimals (such as One-third) that are not of the power of the two, and we can only increase the precision by increasing the length of the binary.

2.42 IEEE floating point representation

This paragraph of the book is very good, I do not watch, directly transcription:

2.43 Numeric instances

Don't blame me for these sections, really, I said it is difficult to understand, the book and Mao very Good understanding ...

There is a problem with the figure (the diamond should be a non-normalized value), the non-normalized value is particularly suitable to represent very close to 0 of the number, and the special value is used to denote infinity ...

Feel this part of the focus is to understand the floating point machine representation, as long as the clear conversion rules, can complete floating-point number and decimal decimal conversion is OK ... There is also a point where we can see the relationship between integers and floating-point numbers ...

2.44 rounding

Rounding here by default is rounded to even, also known as the closest rounding, personally think the book this place is very problematic, is one of the few failures of the book (Do not speak with me English version, my English version also read, as ambiguous) ... This rounding is actually very simple, for example, we want to round a floating-point number to an integer, for example, 1.1, we will certainly get the result 1, in this case is called the recent rounding, if hit 1.5, then it is 1 and 21 like, then it is necessary to consider even rounding, That is, if this is not the same distance from both sides of the boundary, only the most recent rounding is required ... (binary 0 is even) the other three to 0, rounding up or down to say no more ...

2.4.5 floating Point arithmetic

The IEEE standard uses simple rules to determine. Floating-point unit designers use some techniques to avoid accurate calculations, to ensure that proper rounding is necessary, and to define more reasonable rules for parameters with special worth of floating-point arithmetic, such as 1 divided by 0 to get positive infinity and so on ... At the same time, because of the introduction of the rounding mechanism, the calculation of floating-point numbers is exchangeable and can not be combined (in accordance with the Exchange law and not conform to the law of Union) ... For example, X + y must be equal to Y + x, but the results (3.14 + le10)-Le10 and 3.14 + (LE10-LE10) are 0 and 3.14 respectively ...

Because the addition of floating-point numbers does not conform to the binding law, this can have some effect on compiler writing.

For example, operations on the following floating-point numbers:

x = a + B + C;

y = B + C + D;

If the compiler wants to reduce the addition of floating-point numbers once, the following optimizations are made:

T = B + C;

x = a + t;

y = t + D;

The result may be different, so the compiler will try to avoid the optimizations that affect this functionality ... (Remember when you write the compiler ...)

At the same time floating-point addition satisfies monotonicity: for example a >= B, then for any A, B, X (Nan does not count), there are X + a >= x + b ... (Integer operations overflow, so not satisfied) ...

Floating-point multiplication is also commutative and monotonic but not binding, and there is no distributive ... (These things feel can not remember, as long as the later thought in the blog to remember to come back to check on the line)

2.46 floating-point numbers in C language

The C language standard does not stipulate that the floating-point number must use the IEEE standard, but generally with float, double for IEEE single-precision and double-precision floating-point number, for the infinity of such, generally defined in the header file, different system platform is not the same ... Here are some of the conversion rules for the int, float, and double in the C language:

For exercises 2.54:

A: Yes (to remember a little, int and float to double no loss) ...

B: Error (some large int although float can represent a sufficient range, but often with insufficient precision)

C: Error

D: For

E: Correct

F: Correct

G: Correct (remember that floating-point overflow is not like an integer, this equation overflows to positive infinity at most)

H: if (remember if there is a number close to the limit, then the result of adding with it is that a number is directly abandoned, such as when F is large, and D = 1.0, then f + D is f, f-f equals 0.0, and the right equals 1.0)

2.5 Summary

Let me summarize it myself, this chapter is actually two points:

1. Overflow of integers and integers ...

1. Overflow Problem of addition operation

1. The unsigned number overflow, the result is less than any one number

2. The complement of the number of overflow, either two positive one negative, or two negative one positive.

2. Overflow problem of multiplication operation

The result is over 32-bit overflow, there is no regularity to follow.

3. Whether overflow or not, in accordance with the Exchange law, binding law, distribution law.

2. Rounding and overflow of floating-point numbers and floating-point numbers ...

1. The representation of floating-point numbers complies with the IEEE standard ...

2. Floating-point numbers are rounded by default to near-to-even

3. Floating-point number is large when overflow to positive infinity, very small to negative infinity overflow, near 0 o'clock to 0 overflow.

4. Due to the presence of rounding, the floating-point arithmetic does not conform to the distribution law and the binding law, only in accordance with the Exchange law and monotonicity, which should be particularly careful.

Homework Homework No answer, now just want to quickly into the third chapter of the Assembly, do not write ...

Representation and processing of information (4)

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.