Precendence Park, Ankeny, Iowa Because I needed a picture for this post, and I really wonder what prompted this name choice. |
6/2(1+2)If you try to evaluate it, but you don't know and follow the rules of precedence, you might get the wrong answer. Depending on whether you divide or multiple first you could get 9 or 1.
There are rules for precedence. I think they are the same for computer programs and high school algebra, but I'm not be sure. (Teachers don't you fill me up with your rules.)
They made a big deal out of it at college when I was studying computer science, and maybe if you spent all day coding equations they would become second nature to you.
I've done a little bit of mathematical coding, so I've dealt with this problem and I don't like it, so I use parentheses. Parentheses overrule all other rules, so if you don't want your equation misinterpreted, load it up with parentheses. That way there can be no doubt as what you mean.
If I recall the rules correctly, they are:
- Parentheses
- Multiplication and division, in order, left to right
- Addition and subtraction, in order, left to right
- would be (1+2) = 3
- 6 / 2 = 3
- 3 x 3 = 9
and if you want to feed it to a computer you also need the symbol for multiplication, i.e. (6/2) * (1+2).
I don't know of any programming language that understands implicit multiplication, i.e. 2(3x).
Via Iaman
No comments:
Post a Comment