Float representation of computer floating point numbers

Source: Internet
Author: User
Tags float range

This articleArticleIt is easy to understand, so let's take a look. You must have a clear understanding of the original code, reverse code, complement code, and transfer code of the computer principle. For more information, see ieee754. Otherwise, you may not understand it. Your opinion or opinion is enclosed in brackets. I think the implementation of floating point numbers also has a lot to do with the compiler.

 

I looked at it carefully two days ago and thought it would be too unfriendly to study computers if they didn't say how to represent floating-point numbers. A lot of people have written this article. I want to deepen my impression, and I hope that I can write more deeply and easily.

Let's talk about the 32-bit float type.
A floating point number X, expressed:
X = A * 2E
Here e Represents the index, and a represents the ending number. Inside the computer, they are all represented in binary. A uses binary scientific notationBecause the first digit in scientific notation is always 1 (except 0), the first digit is omitted. E indicates that a negative number is displayed, so 127 is added, and 127 is subtracted from the actual operation.

IEEE stipulates that the 32-bit float is split into the following format, and the left side is high:
0 0000 0000 0000000 00000000 00000000
Highest, 32nd-24 bits, 8-23-1 bits in total
Symbol digit index digit tail Digit
0 is positive, 1 is negative-127 ~ + 128 0 ~ 0x 7f FF

The float range is-3.40282 * e38 ~ + 3.40282 * e38

Generally, it is a decimal number. to convert it to binary. to convert it to binary, the part greater than 1 is divided by 2 to take the remainder, and the part smaller than 1 is multiplied by 2 to take the integer.(In the computer principles class, I will remember this sentence after talking about so many things)
For example, if 8.5 is converted to a binary value of 1000.1, it will be 1.0001*23 if it is processed in scientific notation. Note: Because 1.0001 is the first 1 to be removed (Scientific notation), So it becomes 0001, 3 needs to add 127 to become 130(For the code transfer operation, the result of adding 2 ^ n to the original code minus 1, where N is the data bit length)The binary value is 10000010, which is expressed:
0 1000001000010000000000000000000
The hexadecimal format is 0x41 08 00. Generally, the intel series CPU bytes are in the order of little-Endian (high bytes are placed behind). Therefore, the memory storage order is as follows: 0x00 00 08 41. This completes a floating point representation.

Note: Floating Point Number 0.0 indicates 0x00 00 00 in the computer.

So what is the precision of floating point numbers? When we use binary to represent a part greater than 1, there is no problem. Divide by 2 and continue. The last digit is definitely not 1 or 0. What about the decimal part? For example, 0.8
Indicates 0.8
* 2
1.6-1 = 0.6
* 2
1.2-1 = 0.2-0
. * 2
0.4-0
* 2
0.8-0
In this case, the loop means that the binary value of 0.8 is 0.11000 11000 ...... keep repeating, and if our computer indicates that 0.8 can only take the first 25 digits after 0 (the first 1 is omitted, ^_^), it means that if it is 0.80000000000000000000000001, the value represented by it is actually the same as that of 0.8. Therefore, we have no reference to comparing float-type numbers with a = B. Generally, ABS (a-B) <0.000001 is used. (0.000001 should be binary, right? This involves the knowledge of real numbers in mathematics. Formula | a-B | <C to-C <a-B <C) And so on, it is equal by default, so there is a classic precision problem.

What about double type? We can draw the Image Based on the float type.
The double type is only about 64-bit, which is twice the float type, but it cannot escape the precision of the five fingers.
IEEE-defined double type,
64th bits 63-53 52-1
Symbol bit index bit (-1023 ~ + 1024) tail Digit

So the range of double type is-1.79769 * e308 ~ + 1.79769 * e308
A few more characters are used, indicating that the range is much larger. In fact, it is essentially the same as the float type.

It seems that computers are used for computation, and there is nothing false at all. The so-called machine intelligence is also a human addition, so there is no need to doubt it.

 

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.