Most of the unexpected results arise from truncation which occurs either when converting from floating-point to integer,
1 2 3 4 5
|
int d = 3599.99999999999;
cout << d << '\n';
int e = round(3599.99999999999);
cout << e << '\n';
|
3599
3600 |
or when exceeding the capacity of an integer.
1523*1523*1523*4 gives
14130570668
which requires more than 32 bits, and is truncated to
1245668780
The difference is 3*2^32
That leads to the incorrect result 1304460194.187
Recommendations. Use type double for floating-point work. Avoid mixing integer and floating-point types in the same calculation.
Constants such as 4 or 3 are integers, use 4.0 and 3.0 which are type double instead.
edit:
note also,
cout << 3599.99999999999 << '\n';
result is
Since the default precision for cout is 6 significant digits, the displayed result is rounded before being shown, the extra digits are still there, they are simply not displayed.