LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Order of Operations

Root / FAQs / [.]

12Me21Created:
wrongIn section 32 of the manual (Standard BASIC Spec.) it has a table showing the order of operations in SB.
  • Contents enclosed in ()
  • - (Unary), NOT (One's complement), ! (Logical inversion)
  • *, /, DIV (Integer division), MOD
  • +, - (Binomial)
  • <<, >> (Shift)
  • ==, !=, <, <=, >, >=
  • AND, OR, XOR (Bitwise operations)
  • &&, || (Logical operators. With shortcuts)
This is incorrect
The real order is: (like almost every programming language)
  • -(Unary), !(logical), NOT(bitwise)
  • *, /, DIV, MOD(Integer)
  • +, -
  • <<, >>(arithmetic)
  • <, <=, >, >=, ==, != *
  • AND(bitwise)
  • XOR(bitwise), OR(bitwise) *
  • &&(logical)
  • ||(logical)

W-...wait, I've been using AND this whole time when I should've been using the logical version &&? Does SB support the caret power notation (^)?

No, you have to use POW(base,exponent) :(

W-...wait, I've been using AND this whole time when I should've been using the logical version &&? Does SB support the caret power notation (^)?
Don't most programming languages use the caret for XOR anyways?

W-...wait, I've been using AND this whole time when I should've been using the logical version &&? Does SB support the caret power notation (^)?
Don't most programming languages use the caret for XOR anyways?
yes, but many BASIC dialects use ^ for exponents, and xor is already XOR in SB, so they *could* (should) have done it.

Are operands on the same level evaluated right-to-left, or left-to-right? Or does it depend? Also the fact that there isn't a logical XOR really annoys me.

with something like A()*B()*C(), it seems to evaluate: C, B, A, A*B, AB*C. functions are normally done right to left, but operators with the same precidence are usually left to right like in normal math. An exception is A()&&B() where A is evaluated first, and B only checked if A is not 0. I think some operations (== maybe?) are done right to left, like A==B==C might check B==C first (but I'm not sure)

Are contents enclosed in parentheses not calculated?

Are contents enclosed in parentheses not calculated?
They are, but parentheses aren't operators so they don't belong on the list. Their contents must be evaluated first for any system to make sense, so there's no reason to include them here.

Okie dokie