I recently noticed something potentially unpleasant about the way MS Excel handles mathematical order-of-operations. It seems that Excel places "negation" higher than exponentiation in its order-of-operations scheme. Typically, when constructing a spreadsheet, "negation" is simply an implicit subtraction from zero (or multiplication by minus one, if you prefer) i.e. -3 instead of 0-3 (or -1*3). As you may recall from grade school, addition/multiplication is done AFTER exponentiation. For a quick example of the problem, type the following two formulas into Excel:
-(2*2)^2
-((2*2)^2)
These two formulas are functionally equivalent to 0-(2*2)^2 and should return -16. However, Excel handles the negation sign prior to the exponent, interpreting the top formula as (0-(2*2))^2 = 16. The bottom format is required for this code to execute correctly.
The engineers I work with (I'm a Mech. E) were horrified when I showed this to them, as we do a lot of spreadsheet models and no one was aware of this.
Now, according to Microsoft's Knowledge Base, this was carried over from the initial release and was maintained for version consistency:
Link
Does anyone know why Microsoft did it this way? The only precedent I can find is the use of negation as a logical device (i.e. Not) in software. In that case, it could be prioritized above a binary multiply or add. I suppose if you then viewed exponentiation as a function consisting of multiple multiplications, you might come up with MS' order of ops. However, I can't, for the life of me, come up with a situation where this would be the correct interpretation, and certainly not in a typical spreadsheet.
Sorry for being longwinded, but if anyone can shed some light on this, I am quite curious.
Cliffs:
1) MS Excel does "negation" before exponentiation
2) Why?
-(2*2)^2
-((2*2)^2)
These two formulas are functionally equivalent to 0-(2*2)^2 and should return -16. However, Excel handles the negation sign prior to the exponent, interpreting the top formula as (0-(2*2))^2 = 16. The bottom format is required for this code to execute correctly.
The engineers I work with (I'm a Mech. E) were horrified when I showed this to them, as we do a lot of spreadsheet models and no one was aware of this.
Now, according to Microsoft's Knowledge Base, this was carried over from the initial release and was maintained for version consistency:
Link
Does anyone know why Microsoft did it this way? The only precedent I can find is the use of negation as a logical device (i.e. Not) in software. In that case, it could be prioritized above a binary multiply or add. I suppose if you then viewed exponentiation as a function consisting of multiple multiplications, you might come up with MS' order of ops. However, I can't, for the life of me, come up with a situation where this would be the correct interpretation, and certainly not in a typical spreadsheet.
Sorry for being longwinded, but if anyone can shed some light on this, I am quite curious.
Cliffs:
1) MS Excel does "negation" before exponentiation
2) Why?
