

Ask HN: Why is -2^2 = -4 instead of 4? - oscardelben

I'm puzzled. I'm wondering why if I type in wolfram alpha -2^2 I get -4 instead of 4. Same on google or anywhere else.<p>I get confused because in a book that I'm studying the author uses -2^2 to indicate 4, which looks correct to me. So who's correct? I'm sure I'm missing something obvious here.<p>Edit:<p>My girlfriend (which is not a programmer), says that perhaps the computer is giving precedence to the exponentiation, and then adding the -. So it would be -(2^2).<p>Edit2:<p>Thanks for all the answers. It's clear to me now.
======
param
Its the bodmas rule. Wolfram is interpreting -2^2 to mean -(2^2). I am sure if
you write (-2)^2 in wolfram, it will give you 4.

<http://www.mathsisfun.com/operation-order-bodmas.html>

~~~
sandipc
interesting, I've never heard of BODMAS... just PEMDAS.

Same thing, different acronym. (parentheses, exponents, multiply/divide,
add/subtract)

------
monk_the_dog
I don't know wolfram alpha, just thought I'd point out something interesting:
if ^ is the xor operator, then -2^2==(11111110)xor(00000010)==(11111100)==-4

------
_0ffh
Maybe at Wolfram Alpha the "^" binds stronger than the unary "-"?

~~~
_0ffh
I have checked and confirmed that! -2^2 = -(2^2) = -4 (-2)^2 = 4 OP could have
noticed - you can see it in the input interpretation box!

------
mariuskempe
You mean (-2)^2.

