How come C can represent the floating points 1.75 and 1.05 exactly, but not 2.45 and 0.7?
In the code below I have tried to demonstrate what I mean. 1.75 - 1.05 - 0.70 is exactly 0, but 1.75 - 2.45 - 0.70 is not, but the amount of decimal places is the same.
C code:
int digs = DECIMAL_DIG;
printf("1.75 - 1.05 -0.70: %.*e \n",digs, A1-A3-A4);
printf("1.75 - 2.45 - 0.70: %.*e \n",digs, A1-A2+A4);
printf("\n2.45: %.*e \n",digs, 2.45);
printf("\n1.75: %.*e \n",digs, 1.75);
printf("\n1.05: %.*e \n",digs, 1.05);
printf("\n0.70: %.*e \n",digs, 0.70);
printf("\n1.00: %.*e \n",digs, 1.00);
Output:
1.75 - 1.05 -0.70: 0.000000000000000000000e+000
1.75 - 2.45 - 0.70: -2.220446049250313100000e-016
2.45: 2.450000000000000200000e+000
1.75: 1.750000000000000000000e+000
1.05: 1.050000000000000000000e+000
0.70: 6.999999999999999600000e-001
1.00: 1.000000000000000000000e+000