1. 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.
    Dismiss Notice

Order of Operations Conventions

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

  1. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

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

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

    would give the error "Expression too complicated"
     
  2. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    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.
     
  3. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,916
    Likes:
    1,097
    No, PDP-11, RSTS-11 OS, Basic-Plus I had access to the OS source at that time.
     
  4. dave

    Dave New Member

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


     
  5. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    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. atferrari

    atferrari Well-Known Member

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

    atferrari Well-Known Member

    Joined:
    Oct 8, 2003
    Messages:
    2,812
    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. atferrari

    atferrari Well-Known Member

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

    Excerpt MrAl.jpg
     
    • Like Like x 1
  9. misterT

    misterT Well-Known Member Most 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 Like x 1
  10. throbscottle

    throbscottle Well-Known Member

    Joined:
    Feb 1, 2012
    Messages:
    1,783
    Likes:
    113
    Location:
    Nuneaton, Warwickshire, UK
    What a remarkably useful post! Thanks :)
     
    • Funny Funny x 1
  11. Ratchit

    Ratchit Well-Known Member

    Joined:
    Mar 12, 2008
    Messages:
    1,934
    Likes:
    78
    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 Like x 1
    • Agree Agree x 1

Share This Page