top | item 32494296

(no title)

brospars | 3 years ago

There is something wrong with the order of operations. When I type 2+2*2-6 i get -6 which should be 0.

discuss

order

sneak|3 years ago

I would think this might be the first unit test one would write for a calculator program.

simonz05|3 years ago

Yep, this should be evaluated as `(- (+ 2 (* 2 2)) 6)`

unsafecast|3 years ago

It looks like APL order? Right-to-left.

JackFr|3 years ago

No. It’s not right to left. It’s just weird:

  3 ^ 1 * 2   6
  3 ^ 1 / 2   1.73205
  3 ^ 1 + 2   5
  3 ^ 1 - 2   1

bdwjn|3 years ago

Oh there's more:

9 - 3 ^ 2 = 0

9 -3 ^ 2 = 18 ???

pi = 3.1415926536

2 pi = 5.1415926536 ???

sin(3.1415926536 radians) = -0

sin(pi radians) = Incompatible units ???

wizofaus|3 years ago

Seems to assume + if an arithmetic operator is missing?