floating-point subtraction problems python3

First, the direct determination method: direct determination of all loaded into the binary integer part, if the number of bits is equal to the subtraction value is equal to, if not equal, the subtraction results will not equal the big you want to compare results. 
    As in the case of 66.6-60.6 == 6.0, 66.6 binary: 1000010.100110011001100110011001100110011001100110011 
                           60.6 Binary: 111100.10011001100110011001100110011001100110011001101   
                           Binary 6.0: 110 
we can see that the length of an integer 60.6 66.6 less than one, and 4-byte floating-point number is stored as 32-bit , where the first bit is the sign bit, 23 bit number used to hold back, the median is the integer and fractional part, so the above answers came out, a short integer, decimal time will certainly be a retention bits, and calculates a decimal integer conversion is no loss of accuracy, but because they lack more decimal lead to a loss of accuracy, it is impossible to equal 6.0 66.6-60.6 result, only less than 6.0 or greater than, entitled examples ., due to the long retention 60.6 decimals so spaced less than 6.0 results 

summary: in any other case itself according to the above calculation, the first step: a binary number is converted directly, to see whether the same number of bits, look 23 (decimal integer bits and the total length)   


to find a suitable picture: 
attach a picture:     

floating-point calculation The memory divided into three parts: 
   1. the sign bit (sign): float and double are a sign bit, 0 represents a positive number, 1 for negative 
   2. exponent (exponent The): stored in scientific notation index part using the shifted stored
   3. The bit mantissa (fraction): stored mantissa scientific notation 


storage float follows:

Guess you like

Origin www.cnblogs.com/caiwenjun/p/11978502.html