Oh my god now this is going to be Lemmy’s top thread for 6 months, isn’t it?
Btw, yeah I’m with you on this, you just need to know the priorities and you’re good, because the order doesn’t matter for operations with the same priority
Except it does matter. I left some examples for another post with multiplication and division, I’ll give you some addition and subtraction to see order matter with those operations as well.
Right to left:
1 + (2 - (3 + 4))
1 + (2 - 7)
1 + (-5) = -4
Left to right:
((1 + 2) - 3) + 4
(3 - 3) + 4 = 4
Edit:
You can argue that, for example, the addition first could be (1 + 2) + (-3 + 4) in which case it does end up as 4, but in my opinion that’s another ambiguous case.
Oh my god now this is going to be Lemmy’s top thread for 6 months, isn’t it?
Btw, yeah I’m with you on this, you just need to know the priorities and you’re good, because the order doesn’t matter for operations with the same priority
Except it does matter. I left some examples for another post with multiplication and division, I’ll give you some addition and subtraction to see order matter with those operations as well.
Let’s take:
1 + 2 - 3 + 4
Addition first:
(1 + 2) - (3 + 4)
3 - 7 = -4
Subtraction first:
1 + (2 - 3) + 4
1 + (-1) + 4 = 4
Right to left:
1 + (2 - (3 + 4))
1 + (2 - 7)
1 + (-5) = -4
Left to right:
((1 + 2) - 3) + 4
(3 - 3) + 4 = 4
Edit: You can argue that, for example, the addition first could be
(1 + 2) + (-3 + 4)
in which case it does end up as 4, but in my opinion that’s another ambiguous case.