this post was submitted on 03 Dec 2023
3 points (100.0% liked)

196

16542 readers
2796 users here now

Be sure to follow the rule before you head out.

Rule: You must post before you leave.

^other^ ^rules^

founded 1 year ago
MODERATORS
 
top 10 comments
sorted by: hot top controversial new old
[–] mindbleach@sh.itjust.works 2 points 11 months ago (1 children)

Different compilers have robbed me of all trust in order-of-operations. If there's any possibility of ambiguity - it's going in parentheses. If something's fucky and I can't tell where, well, better parenthesize my equations, just in case.

[–] linuxdweeb@lemm.ee 0 points 11 months ago (1 children)

This is best practice since there is no standard order of operations across languages. It's an easy place for bugs to sneak in, and it takes a non-insignificant amount of time to debug.

[–] SmartmanApps@programming.dev 1 points 8 months ago

there is no standard order of operations across languages

Yes there is. The rules of Maths are universal.

It’s an easy place for bugs to sneak in

But that's because of programmers not checking the rules of Maths first.

[–] Pavidus@lemmy.world 1 points 11 months ago (1 children)

There's quite a few calculators that get this wrong. In college, I found out that Casio calculators do things the right way, are affordable, and readily available. I stuck with it through the rest of my classes.

[–] queue@lemmy.blahaj.zone 1 points 11 months ago (1 children)

Casio does a wonderful job, and it's a shame they aren't more standard in American schooling. Texas Instruments costs more of the same jobs, and is mandatory for certain systems or tests. You need to pay like $40 for a calculator that hasn't changed much if at all from the 1990's.

Meanwhile I have a Casio fx-115ES Plus and it does everything that one did, plus some nice quality of life features, for less money.

[–] AceFuzzLord@lemm.ee 1 points 11 months ago

If you're lucky, you can find these TI calculators in thrift shops or other similar places. I've been lucky since I got both of my last 2 graphing calculators at a yard sale and thrift shop respectively, for maybe around $40-$50 for both.

[–] queue@lemmy.blahaj.zone 0 points 11 months ago* (last edited 8 months ago) (1 children)

For anyone like me who has math as their worst subject: PEMDAS.

PEMDAS is an acronym used to mention the order of operations to be followed while solving expressions having multiple operations. PEMDAS stands for P- Parentheses, E- Exponents, M- Multiplication, D- Division, A- Addition, and S- Subtraction.

So we gotta do it in the proper order. And remember, if the number is written like 2(3) then its multiplication, as if it was written 2 x 3 or 2 * 3.

So we read 8/2(2+2) and need to do the following;

  • Read the Parentheses of (2 + 2) and follow the order of operations within them, which gets us 4.
  • Then we do 2(4) which is the same as 2 x 4 which is 8
  • 8 / 8 is 1.

The answer is 1. The old calculator is correct, the phone app which has ads backed into it for a thing that all computers were invented to do is inaccurate.

[–] a_fine_hound@lemmy.world 0 points 11 months ago* (last edited 11 months ago) (1 children)

Well that's just wrong... Multiplication and division have equal priorities so they are done from left to right. So: 8 / 2 * (2 + 2)=8 / 2 * 4=4 * 4=16

[–] nutcase2690@lemmy.dbzer0.com 0 points 11 months ago (1 children)

Not quite, pemdas can go either from the left or right (as long as you are consistent) and division is the same priority as multiplication because dividing by something is equal to multiplying by the inverse of that thing... same as subtraction being just addition but you flip the sign.

8×1/2=8/2 1-1=1+(-1)

The result is 16 if you rewrite the problem with this in mind: 8÷2(2+2)=8×(1/2)×(2+2)

[–] SmartmanApps@programming.dev 0 points 8 months ago

8÷2(2+2)=8×(1/2)×(2+2)

No, that's wrong. 2(2+2) is a single term, and thus entirely in the denominator. When you separated the coefficient you flipped the (2+2) into the numerator, hence the wrong answer. You must never add multiplication signs where there are none.