Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Why is there a big subtraction error in calculating similar values on a computer with a short word length?
Why is there a big subtraction error in calculating similar values on a computer with a short word length?
First, you can do the experiment with a standard 10-bit calculator:

Calculate 900000 2-899998 * 900002.

The calculator shows zero. But in fact, using the square difference formula learned in middle school, we can know that their difference should be 4. The reason is that the calculator calculates 900002 and 899998 * 900002 respectively. Because there are not enough digits in the calculator, these two results are expressed as 8.1*1011by scientific counting method. So the result after subtraction is zero.

Similarly, for computers with short word length, the expression ability of plastic data ("int", which represents the whole data in binary, you can refer to the integer displayed on the calculator) is not enough, so for data with large value or long length, it is necessary to convert it into double-precision data ("double", which is similar to scientific counting methods, such as 900000 2 and 89998 * 9000 above. The data representation method in computer is slightly different from this, but it is a scientific counting method in essence, which will lead to the loss of effective figures. Therefore, in the actual numerical calculation, we should avoid such number subtraction.