浮点数在计算机内的存储是怎样的呢?以双精度浮点数为例来说吧:
Most nonzero floating-point numbers are normalized. This means they can be expressed as : x = ±(1 + f) *2^e
Double-precision floating-point numbers are stored in a 64-bit word, with 52bits for f, 11 bits for e, and 1 bit for the sign of the number. The number 1 was not actually stored for its default property . In effect, the IEEE format packs 65 bits of information into a 64-bit word.
这就是双精度浮点(double)型数据,占8 个字节(64位)内存空间。但是其数值范围为1.7E-308~1.7E+308,双精度完全保证的有效数字是15位,也就是那对应f的52位的二进制数所能表示的f的十进制数的范围。
eps is the distance from 1 to the next larger floating-point number. For IEEE double-precision, eps = 2^(-52).即是f的最小值。The approximate decimal value of eps is 2.2204·10 −16.
In either case, you can say that the roundoff level is about 16 decimal digits.16位只是部分数值的精确度有保证。
关于小数0.1的存储细节,可以参考这篇博客。