3 ms·
Ask HN: Why is -2^2 = -4 instead of 4?
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.
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.
Edit:
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).
Edit2:
Thanks for all the answers. It's clear to me now.
- _0ffh 16y agoMaybe at Wolfram Alpha the "^" binds stronger than the unary "-"?
- _0ffh 16y agoI 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 16y agoYou mean (-2)^2.
- param 16y agoIts 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 http://www.mathsisfun.com/operation-order-bodmas.html
- sandipc 16y agointeresting, I've never heard of BODMAS... just PEMDAS. Same thing, different acronym. (parentheses, exponents, multiply/divide, add/subtract)
- monk_the_dog 16y agoI 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