I am trying to subtract a small double number from a large double number in C++. Here is my code
int main()
{
double a=166666166667000000.000000;
double b=1.0;
double c=4.0;
double d=10.0;
double ans_b=a-b;
double ans_c=a-c;
double ans_d=a-d;
printf("%f\n%f\n%f\n",ans_b,ans_c,ans_d);
return 0;
}
This Code is giving me following output -
166666166667000000.000000
166666166667000000.000000
166666166667000000.000000
However, all three are supposed to be different. Why does subtraction with double type behaves this way?