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

**URL:** <https://discourse.processing.org/t/please-explain-this-to-me-multiplying-done-before-dividing/40410>\
**Category:** Beginners\
**Created:** [January 2, 2023, 5:42pm UTC](https://discourse.processing.org/t/please-explain-this-to-me-multiplying-done-before-dividing/40410 "2023-01-02T17:42:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrinalino](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@adrinalino](https://discourse.processing.org/u/adrinalino)\
**Post date:** [January 2, 2023, 5:42pm UTC](https://discourse.processing.org/t/please-explain-this-to-me-multiplying-done-before-dividing/40410/1 "2023-01-02T17:42:48Z")

</div>

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?  
Thanks for your help.  
Cheers,  
Adrian.

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

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

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 2, 2023, 6:00pm UTC](https://discourse.processing.org/t/please-explain-this-to-me-multiplying-done-before-dividing/40410/2 "2023-01-02T18:00:24Z")

</div>

> [@adrinalino](#):
>
> I was under the impression that multiplying was done before dividing

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 /

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [January 2, 2023, 6:16pm UTC](https://discourse.processing.org/t/please-explain-this-to-me-multiplying-done-before-dividing/40410/3 "2023-01-02T18:16:25Z")

</div>

Hi @adrinalino,

That’s the rules …

> **[Order of Operations - PEMDAS](https://www.mathsisfun.com/operation-order-pemdas.html)**
>
> Learn how to calculate things in the correct order. Calculate them in the wrong order, and you can get a wrong answer!

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![adrinalino](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@adrinalino](https://discourse.processing.org/u/adrinalino)\
**Post date:** [January 2, 2023, 6:27pm UTC](https://discourse.processing.org/t/please-explain-this-to-me-multiplying-done-before-dividing/40410/4 "2023-01-02T18:27:30Z")

</div>

Thanks guys, we’re taught this differently over in the Netherlands but thanks for the clarification.  
Cheers,  
Adrian.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 2, 2023, 6:31pm UTC](https://discourse.processing.org/t/please-explain-this-to-me-multiplying-done-before-dividing/40410/5 "2023-01-02T18:31:16Z")

</div>

> **[Java syntax | Operators](https://en.wikipedia.org/wiki/Java_syntax#Operators)**
>
> Operators in Java are similar to those in C++. However, there is no delete operator due to garbage collection mechanisms in Java, and there are no operations on pointers since Java does not support them. Another difference is that Java has an unsigned right shift operator (\>\>\>), while C's right shift operator's signedness is type-dependent. Operators in Java cannot be overloaded.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [January 2, 2023, 7:01pm UTC](https://discourse.processing.org/t/please-explain-this-to-me-multiplying-done-before-dividing/40410/6 "2023-01-02T19:01:44Z")

</div>

Hi @adrinalino,

> [@adrinalino](#):
>
> Thanks guys, we’re taught this differently over in the Netherlands

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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 2, 2023, 8:43pm UTC](https://discourse.processing.org/t/please-explain-this-to-me-multiplying-done-before-dividing/40410/7 "2023-01-02T20:43:25Z")

</div>

> [@mnse](#):
>
> If that would be the case, your math in the Netherlands would be broken.

I think the confusion is b/c computational operator for division `/` is equivalent to mathematical operator `÷`

> **[Division sign](https://en.wikipedia.org/wiki/Division_sign)**
>
> The division sign (÷) is a symbol consisting of a short horizontal line with a dot above and another dot below, used in Anglophone countries to indicate mathematical division. This usage, though widespread in some countries, is not universal and the symbol has a different meaning in other countries. Its use to denote division is not recommended in the ISO 80000-2 standard for mathematical notation.
> The obelus, a historical glyph consisting of a horizontal line with (or without) one or more dot...

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.

---

<div class="post-metadata">

**Author:** ![adrinalino](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@adrinalino](https://discourse.processing.org/u/adrinalino)\
**Post date:** [January 12, 2023, 10:52pm UTC](https://discourse.processing.org/t/please-explain-this-to-me-multiplying-done-before-dividing/40410/8 "2023-01-12T22:52:10Z")

</div>

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)  
o : optellen (add)  
a : aftrekken (subtract)

Cheers,  
Adrian.
