Forum Discussion
Excel wrong calculation
I typed in the formula "-B7^2 + 123.4" and it was parsed as (-B7)^2 + 123.4 rather than as -(B7^2) + 123.4 Ouch!!!
It is documented in Calculation operators and precedence in Excel
Under Operator precedence, you'll see that - (negation) is evaluated before ^ (exponentiation). This is different from common practice in mathematics.
- warrenf320Oct 21, 2024Copper Contributor
Thanks for pointing out MS's approach to expression evaluation. It is a pity that MS choose to not follow mathematical tradition. I have advanced degrees in math and physics and I would not have expected this behavior. I have even written expression parsers. Do common programming languages do the same, or has Excel marched down its own unique path? For example, I use Matlab from Mathworks and it reports -5^2 + 25 as 0, not as 50. Python reports -5**2 + 25 as 0 too.
- SergeiBaklanOct 22, 2024Diamond Contributor
That's common, at least in data modelling. You may check in Google Sheets and other spreadsheet software (not sure about all of them), -5**2 + 25 returns 50.
Another story is what for negation and subtraction here is used the same "-" symbol. In some languages they are different.