4
$\begingroup$

What does $-2^2$ evaluate to? My wife is upgrading her math & I'm quite uncertain how to answer.

is it the same as $(-2)^2$ or is it the same as $-(2^2)$?

at the heart of this is whether the minus sign is associated with the 2 or the expression $2^2$.

thank you! mp

  • 0
    thank you TheChaz--corrected the title. thank you arturo for setting the super script...didn't see how to do that. your reply is consistant with the book's chapter..."orders of operation". thank you all.2011-09-30

1 Answers 1

5

There are different conventions. In mathematics the usual one is to write $(-2)^2$ if you want to raise a negative number to a power, whereas $-2^2$ usually means $-(2^2)$.

This is, however, not completely universal. For example, many programming languages (that otherwise follow mathematical conventions for arithmetic expressions) consider a unary minus to bind tighter than any binary operator. In such languages, -2**2 (or whatever their syntax for exponentation is) would mean (-2)**2.

In the end you may be better off checking both interpretations and see which of them makes sense in context. And when writing things yourself, if in doubt err on the side of too many parentheses.

  • 0
    python reports $-2**2 == -4$ as well, and I'm virtually certain magma and mathematica agree. Since you've mentioned fortran, that completely exhausts the languages I have at least passing familiarity with that I know have a binary exponentiation operator.2011-10-01