# Please explain this to me : multiplying done before dividing?

I was pulling my hairs for not being able to solve a simple N-body setup until I noticed something strange. I was under the impression that multiplying was done before dividing but not in this case. Am I overlooking something?
Cheers,

int num = 1000;
float density = num / PI*sq(radius);
println (density);
Result : 5.092958E7

int num = 1000;
float density = num / (PI*sq(radius));
println (density);
// result 0.0019894368


I think they are of the same priority; itâ€™s just whatâ€™s left comes first (from left to right).

It is just + and - is before * and /

1 Like

Thatâ€™s the rules â€¦

Cheers
â€” mnse

2 Likes

Thanks guys, weâ€™re taught this differently over in the Netherlands but thanks for the clarification.
Cheers,

1 Like
1 Like

Thatâ€™s really hard to believeâ€¦
If that would be the case, your math in the Netherlands would be broken. Iâ€™m from your neighboring country and on equal priority (ie. multiply and divide) it is always left to right.

Cheers
â€” mnse

2 Likes

I think the confusion is b/c computational operator for division / is equivalent to mathematical operator Ă·

However, operator Ă· doesnâ€™t behave exactly the same as a mathematical fractional bar: \color{magenta}{3\,\times\,a\over5\,\times\,b}

That is, \color{cyan}{3\,\times\, a\over5\,\times\,b} isnâ€™t the same as \color{red}3\times a\;\div\;5\times b

B/c we donâ€™t want \color{brown}3\times a\;\div\;5 to happen before 5 is multiplied by b.

Weâ€™d need to wrap \color{orange}5\times b w/ parentheses to force multiplication to happen before Ă·: \color{gold}3\times a\;\div\;(5\times b)

Thatâ€™s why expression num/PI * sq(radius) is wrong while num / ( PI*sq(radius) ) is correct.

3 Likes

We learn a frase to remember it â€śMeneer van Dalen wacht op antwoordâ€ť.
m : machtsverheffen (exponentiation)
v : vermenigvuldigen (multiply)
d : delen (devide)
w : worteltrekken (square root)