I would like to know in which order does the explicit type conversion work and in what area does it work. In the next example I receive different results.
float S = 0;
for (int i = 1; i <= 10; i++)
for (int j = 3; j <= 20; j++)
S += (i * j - 5.)/(2. * i + j / 3);
the result is 621.8933
float S = 0;
for (float i = 1; i <= 10; i++)
for (float j = 3; j <= 20; j++)
S += (i * j - 5)/(2. * i + j / 3);
S = 607.3105
float S = 0;
for (int i = 1; i <= 10; i++)
for (int j = 3; j <= 20; j++)
S += (float)(i * j - 5)/(2 * i + j / 3);
S = 621.8933
float S = 0;
for (int i = 1; i <= 10; i++)
for (int j = 3; j <= 20; j++)
S += (i * j - 5)/(2 * i + j / 3.);
S = 607.3105
Obviously the correct result is 607.3105. Why doesn't it promote when I write (float) or multiply by 2., but it works when I divide by 3.? Thanks in advance.