Forum Discussion
error in calculation when sequence is changed
What I don't understand is (-B1^4) should be the same as -(B1^4) but when placed immediately after the bracket, it behaves differently. What is the logic?
msmchou wrote: ``(-B1^4) should be the same as -(B1^4) but when placed immediately after the bracket, it behaves differently. What is the logic? ``
There is no "logic" to understand. Yes, in the language of math, exponentiation has higher precedence than unary minus. So when we write effectively -2^4, it is parsed as -(2^4), and the result is -16. And actually, that is implied by the superscript 4.
But in the language of Excel, MSFT chose the opposite order precedence. Refer to https://support.microsoft.com/en-us/office/calculation-operators-and-precedence-in-excel-48be406d-4975-4d31-b2b8-7af9e0e2878a .
So -2^4 is parsed as (-2)^4, and the result is 16. It is a choice that the Excel designers made. Actually, that choice might have been made by Visicalc or Lotus 1-2-3, and Multiplan/Excel simply chose to be compatible. I don't remember.
There is no right or wrong. Each language makes its own choice about precedence -- and even order of evaluation. In the computer language APL, there is no operator precedence, and expressions are evaluate from right-to-left. So 4*3+2 is 20, not 14.
In Excel, if we want -2^4 to be treated the same as it is in math, we must use parentheses to override the default operator precedence. That is why we must write -(2^4) or -POWER(2,4).
- msmchouDec 01, 2021Copper ContributorMany thanks for your reply!