Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Order of Operations Conventions

Status
Not open for further replies.
I remember a BASIC language that given something like:

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

would give the error "Expression too complicated"
 
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.
 
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.
 
I remember a BASIC language that given something like:

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

would give the error "Expression too complicated"

Complicated maybe, was trying to understand why in heaven anyone would spend his time on that! :wideyed: :hilarious:
 
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.

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!!
 
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.

What I could find

Excerpt MrAl.jpg
 
Wolfram alpha gives the answer -4 to both -2^2 and -2*2.
 
DerStrom8
How does that solve the conundrum that PEMDAS presents? As I currently understand it, applying PEMDAS, -2^2 = -4
However, (a-b)^2 when expanded is a^2 -2ab + b^2. "0-b" is of the same form as (a-b), so (0-b)^2 = b^2, not -b^2.

John

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
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top