[Solved] C++ mathematical problem and 5/4*pi vs 5*pi/4 [closed]


This is because both the following operations are different :

5 * M_PI / 4

and

5 / 4 * M_PI

The operations are performed left to right.

On the first line, 5 * M_PI (int * float) returns a float (15.7…) which is divided by an int (float / int) returning a float (3.9…).

On the second line, 5 / 4 returns an int (int / int) equal to 1, then multiplied by M_PI (int * float) returning a float, which returns exactly M_PI (3.14…)

Which are different results.

2

solved C++ mathematical problem and 5/4*pi vs 5*pi/4 [closed]