The accuracy depends on the value of the original numbers. At a floating point, the computer is number 312 as a scientific designation:
3.12000000000 * 10 ^ 2
The decimal numbers on the left side (mantissa) are fixed. The indicator also has an upper and lower bound. This allows you to display very large or very small numbers.
If you try to add two numbers that are the same in magnitude, the result should remain unchanged in accuracy, since the decimal point should not move:
312.0 + 643.0 <==> 3.12000000000 * 10 ^ 2 + 6.43000000000 * 10 ^ 2 ----------------------- 9.55000000000 * 10 ^ 2
If you try to add a very large and very small number, you will lose accuracy because they must be compressed into the above format. Consider 312 + 12300000000000000000000. First you need to scale a smaller number to line up with a larger one, and then add:
1.23000000000 * 10 ^ 15 + 0.00000000003 * 10 ^ 15 ----------------------- 1.23000000003 <-- precision lost here!
A floating point can handle very large or very small numbers. But he cannot represent both at the same time.
As for adding int and doubling, int immediately turns into double, then the above applies.
source share