// S是符号位,在第0位, P是指数位,用e表示,是第1位到第11位。尾数是储存小数部分(即有效数字),第12到63位,用f表示。e =-4; m =1.1001100110011001100110011001100110011001100110011010 (52位)e =-3; m =1.1001100110011001100110011001100110011001100110011010 (52位)像十进制数有4舍5入的规则一样,二进制也存在类似的规则,简单的说,如果 1.101要保留一位小数,可能的值是 1.1 和 1.2,那么先看 1.101 和 1.1 或者 1.2 哪个值更接近,毫无疑问是 1.1,于是答案是 1.1。那么如果要保留两位小数呢?很显然要么是 1.10 要么是 1.11,而且又一样近,这时就要看这两个数哪个是偶数(末位是偶数),保留偶数为答案。综上,如果第 52 bit 和 53 bit 都是 1,那么是要进位的。这也导致了误差的产生。
我们看下这两个二进制相加
e =-4; m =1.1001100110011001100110011001100110011001100110011010 (52位)+ e =-3; m =1.1001100110011001100110011001100110011001100110011010 (52位)---------------------------------------------------------------------------相加时如果指数不一致,需要对齐,一般情况下是向右移,因为最右边的即使溢出了,损失的精度远远小于左边溢出。 e =-3; m =0.1100110011001100110011001100110011001100110011001101+ e =-3; m =1.1001100110011001100110011001100110011001100110011010--------------------------------------------------------------------------- e =-3; m =10.0110011001100110011001100110011001100110011001100111--------------------------------------------------------------------------- e =-2; m =1.0011001100110011001100110011001100110011001100110100(52位)---------------------------------------------------------------------------=0.010011001100110011001100110011001100110011001100110100=0.30000000000000004(十进制)