Decimal decimals converted to computer stored procedures
Take 9.625 single-precision (32-bit) as an example
Decimal number to binary representation
9.625 = 1001.101 = 1x2 3 + 0x22 + 0x21 + 1x20 + 1x2-1 + 0x2-2 + 1x2-3
Binary number Normalization
IEEE 754 stipulates that the binary representation must be ±d.dd...dxβe by format, (0≤d i <β)
i.e. 1001.101 = 1.001 101 * 23
Store to Computer
Single-precision total length 32 bits
1-23 Statement Mantissa: Because the normalized binary number is only a 1 to the left of the decimal point, so it can be omitted, so that 23 bits are represented by 24 bits. That is, the mantissa is 1.001 101 in 001 101
24-30 means index: 1.001 101 * 23 of 3
31 notation: 1 for negative, 0 for positive
In addition, the digit has 8 digits and can represent a value between 0-255. However, the index is likely to be negative (e.g. 0.625 = 0.101 (binary) = 1.01 * 2-1). Therefore, IEEE 754 specifies that the exponent is an increment of the offset code: the normalized exponent value is +127. So the range of the index changes to-127-128. Then the upper index becomes 130.
According to the above rule, the decimal number after the binary is stored in the computer as: [0] [1000 0010] [0011 0100 0000 0000 0000 000]
Loss of precision
- The number of binary digits after normalization can be much longer than 23 bits, then the computer is stored and loses the latter part. Typical is the 0.58.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the floating-point IEEE 754, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.