Forum Discussion

SergioSolimena's avatar
SergioSolimena
Copper Contributor
Apr 04, 2019

A case of wrong formula calculation in Excel?

I like to have your opinion on the formula calculation performed by Excel in a particolar case that surprised me very much.
This is the case.
A(1,1) =5
A(2,1) = - A1^2
Excel display result in A(2,1) = +25, that is wrong. Te correct result must be -25 because the sign “-“ in not under the square elevation.
I modified the formula in this way:
A(2,1) = - A1^2 + A1
The result is = 30 that is wrong again!
The I changed the order of the two addendum
A(2,1) = A1 - A1^2
Now the result is -20 and, that is correct.
What is your opinion?
Regards and thank.

5 Replies

    • SergioSolimena's avatar
      SergioSolimena
      Copper Contributor
      What you says is clear but it's not correct because in the formula y=-x^2 the result is always negative for any x different from zero.
      I don't have to use the parenthesis.
      As I shown in the example, the same formula y= -A^2 +A =+A- A^2 is written in two different way, only changing the position af the two addendum. The result must be exactly the same. But this not what Excel does.
      This means that it necessary to put attention at the order of the addendum in a sum, and this violates the commuted property of the terms of the sum.
      Because now I know this question I put always attention when i write a formula, but in a complex problem this not simple and reliable.
      • Detlef_Lewin's avatar
        Detlef_Lewin
        Silver Contributor

        SergioSolimena 

        *


        SergioSolimena wrote:
        As I shown in the example, the same formula y= -A^2 +A =+A- A^2 is written in two different way, only changing the position af the two addendum. The result must be exactly the same. But this not what Excel does.
        *

        As you can see in the table provided by PeterBartholomew1 the - (minus sign) in the first case is a negation (a lower order then ^) and in the second case a subtraction (a higher order then ^).

        So by putting parenthesis around A^2 you are changing the order of operation:

        -(A^2)+A = +A-(A^2)

         

    • PeterBartholomew1's avatar
      PeterBartholomew1
      Silver Contributor

      Detlef_Lewin

       

      The help page shows the operator precedence to be as shown in the following table.

      If in doubt, a pair of parentheses work wonders!

       

      Operator

      Description

      : (colon)

      (single space)

      , (comma)

      Reference operators

      Negation (as in –1)

      %

      Percent

      ^

      Exponentiation

      * and /

      Multiplication and division

      + and

      Addition and subtraction

      &

      Connects two strings of text (concatenation)

      =
      < >
      <=
      >=
      <>

      Comparison

       

       

Resources