-1

enter image description here

Why did the designers of Google Sheet choose this operators precedence: -2^2 == (-2)^2 == 4 ?

Any reason?

I prefer the following precedence: -2^2 == -(2^2) == -4.

1 Answer 1

1

It is historical.

Google sheets was released decades after other spreadsheet software was available. Google sheets had to get the same answers as other spreadsheet software would, otherwise there would be zero consistency between providers.

5
  • Thank you very much for your answer. I have not used Microsoft Excel yet. Does Microsoft Excel really return "4" for the input "=-2^2" ?
    – tchappy ha
    May 11, 2021 at 11:35
  • 1
    Yes. I checked before writing the answer. May 11, 2021 at 11:38
  • Thank you very much, mhoran_psprep!
    – tchappy ha
    May 11, 2021 at 11:40
  • 1
    Note that this quirk only applies to the unary operator -. The very similar binary operator - uses the expected precedence — i.e., 10 - 2^2 === 6. May 11, 2021 at 12:17
  • Thank you very much for your information, doubleunary.
    – tchappy ha
    May 11, 2021 at 12:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.