# Order of Operations Conventions

Discussion in 'Mathematics and Physics' started by jpanhalt, Feb 21, 2016.

1. ### KeepItSimpleStupidWell-Known MemberMost Helpful Member

Joined:
Oct 30, 2010
Messages:
9,997
Likes:
1,101
I remember a BASIC language that given something like:

a=(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((1)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

would give the error "Expression too complicated"

2. ### MrAlWell-Known MemberMost Helpful Member

Joined:
Sep 7, 2008
Messages:
11,057
Likes:
963
Location:
NJ
Hi,

Could that have been Sinclair Basic?
I cant remember that far back now, some 36 years ago believe it or not

Back then the stack worked it's way down in memory while the program storage would work it's way up. If they ever met there was sure to be a crash at some point as they both tried to use the same RAM locations. The program eventually tries to 'return' to some random location given by some storage variable which could have been as strange as a voltage reading at some port.

Joined:
Oct 30, 2010
Messages:
9,997
Likes:
1,101

Joined:
Jan 12, 1997
Messages:
-
Likes:
0

5. ### MrAlWell-Known MemberMost Helpful Member

Joined:
Sep 7, 2008
Messages:
11,057
Likes:
963
Location:
NJ

Hi,

Ok, no problem. The order of operations for Sinclair Basic was left to right, but i cant remember if they gave any priority to a minus sign at any point.

Maybe if the number is standing alone we could think of it as a unary operator, with the following reasoning behind that thought...

Squaring a positive number equals a positive number.
Squaring a negative number equals a positive number.

Therefore if we take -2 to be a negative number, then squaring it -2^2 has to lead to 4.
If we take -2^2 to simply be the negative of a (resulting) positive number, then we end up with -4.
The TI89 would return 4 because it has a unary minus sign.
The TI85 if i remember right would return -4 because it did not have a unary minus sign.
Another calculator i had, some Casio model, would return -4 also.
If the calculator handles results as one entity, it would return 4 on a squaring of a previous result: result^2=4.

6. ### atferrariWell-Known Member

Joined:
Oct 8, 2003
Messages:
2,824
Likes:
121
Location:
Buenos Aires - Argentina
Complicated maybe, was trying to understand why in heaven anyone would spend his time on that!

7. ### atferrariWell-Known Member

Joined:
Oct 8, 2003
Messages:
2,824
Likes:
121
Location:
Buenos Aires - Argentina
After learning what a micro (Z80) was with the help of Rodnay Zack(*), my first real exercise was playing with the stack of my Timex 2068. Good thing was that you could see it going up/down on the screen. It took me maybe two more years to believe that (even in cassette) a compiler existed...!

(*) One of the finest books ever!!

8. ### atferrariWell-Known Member

Joined:
Oct 8, 2003
Messages:
2,824
Likes:
121
Location:
Buenos Aires - Argentina
What I could find

• Like x 1
9. ### misterTWell-Known MemberMost Helpful Member

Joined:
Apr 19, 2010
Messages:
2,697
Likes:
368
Location:
Finland
Wolfram alpha gives the answer -4 to both -2^2 and -2*2.

• Like x 1
10. ### throbscottleWell-Known Member

Joined:
Feb 1, 2012
Messages:
1,844
Likes:
115
Location:
Nuneaton, Warwickshire, UK
What a remarkably useful post! Thanks

• Funny x 1
11. ### RatchitWell-Known Member

Joined:
Mar 12, 2008
Messages:
1,961
Likes:
84
One must be careful not to think of a unary operator as an equivalent to an arithmetic subtraction operation. Especially when exponents are involved. For instance, I could write -2^2 = 0 - 2^2 = 0 - 4 = -4 or even -2^2 = -1 * 2^2 = -1 * 4= -4 , both of which give the correct answer for the wrong reason. To be completely unambiguous in defining a unary operator, use parenthesis.

Ratch

• Like x 1
• Agree x 1