: This article mainly introduces the floating point number ieee754. if you are interested in the PHP Tutorial, refer to it. Convert decimal to computer stored procedure
Taking 9.625 single-precision (32-bit) as an example
Convert decimal to binary representation
9.625 = 1001.101 = 1x2 3 + 0x22 + 0x21 + 1x20 + 1x2-1 + 0x2-2 + 1x2-3
Binary number normalization
Ieee 754 requires that the binary representation must follow the format ± d. dd... D × β e, (0 ≤ d I <β)
That is, 1001.101 = 1.001 101*23
Storage to computer
32-bit precision
1-23 indicates the ending number: Because the normalized binary number has only one decimal point on the left side, it can be omitted. in this way, 23 digits are used to represent 24 digits. That is, the ending number is 001 1.001 of 101.
24-30 indicates the index: 3 of 1.001 101*23
31 indicates the symbol: 1 indicates a negative number, and 0 indicates a positive number.
In addition, the index bit has eight digits, which can represent values between 0 and. However, the index may be negative (for example, 0.625 = 0.101 (binary) = 1.01*2-1 ). Therefore, ieee 754 requires that the exponential offset code be added: the normalized exponent value + 127. In this way, the index range is-127-128. Then the above index becomes 130
According to the above rules, the decimal points after binary are stored in the computer as: [0] [1000 0010] [0011 0100 0000 0000 0000]
Precision loss
- It can be seen that the ending part of the normalized binary number may be much longer than 23 bits, so the latter part will be lost during computer storage. Typical is 0.58.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces the floating point number ieee 754, including some content, hope to be helpful to friends who are interested in the PHP Tutorial.