mardi 5 mai 2020

Multiplication/division order(?) confusion [duplicate]

I'm just calculating the volume of the sphere and unexpectedly

  volume = (4/3)*M_PI*pow(radius, 3);
or
  volume = 4/3*M_PI*pow(radius, 3);

gives 392.699 (should be 523.6)

But if I write

volume = 4*M_PI/3*pow(radius, 3);

or

M_PI*4/3*pow(radius_, 3);

Everything is fine. But

M_PI*(4/3)*pow(radius_, 3);

again gives wrong result. I completely have no idea why it's happening so.. Probably I wrote the wrong title, but I just don't understand what's going wrong here..

Aucun commentaire:

Enregistrer un commentaire