Comment on I dunno

<- View Parent
SmartmanApps@programming.dev ⁨3⁩ ⁨days⁩ ago

you’re just using (AS) without realizing it

as per the textbooks 🙄

Conversations around operator precedence can cause real differences in how expressions are evaluated

No they can’t. The rules are universal

you might not underatand it yourself

says someone about to prove that they don’t understand it… 😂

With (AS), 3-2+1 = (3-2)+1 = 1+1 = 2

Nope! With AS 3-2+1=+(3+1)-(2)=4-2=2

This is what you would expect

Yes, I expected you to not understand what AS meant 😂

since we do generally agree to evaluate addition and subtraction with the same precedence left-to-right

It’s only a convention, not a rule, as just proven

With SA, the evaluation is the same

No it isn’t. With SA 3-2+1=-(2)+(3+1)=-2+4=2

you get the same answer

Yep, because order doesn’t matter 🙄 AS and SA both give the same answer

No issue there for this expression

Or any expression

But with AS, 3-2+1 = 3-(2+1)

You just violated the rules and changed the sign of the 1 from a + to a minus. 🙄 -(2+1)=-2-1, not -2+1. Welcome to how you got a wrong answer when you wrongly added brackets to it and mixed the different signs together

So evaluating addition with higher precedence rather than equal precedence yields a different answer

No it doesn’t., as already proven. 3-2+1=+(3+1)-(2)=+4-2=2, same answer 🙄

source
Sort:hotnewtop