View Single Post
  #21   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove Harlan Grove is offline
external usenet poster
 
Posts: 733
Default Excel 2003 SP2 computes the power of a negative number wrong.

Giovanni Ciriani wrote...
Arvi, I do acknowledge that they are separate operators. The expression are
evaluated correctly according to the precedence established by the
programmers. What I'm saying is that the programmer interpreted the specs
regarding negation incorrectly.
The negation should be given priority only if it is in parenthesis, and not
when it is out of parenthesis. That's the only way to keep the rule of
commutativity working.

....

First, commutivity has NOTHING to do with this. Nothing! In ALL
programming languages and all expression-driven numerical computation
software I've seen, unary minus ALWAYS has higher precedence than the
dyadic subtraction operator. -a - b = -(b - -a) (dyadic - is
anticommutative) and -a + b = b + -a (dyadic + is commutative). If you
add other operators, you need to parse the expressions correctly, and
you don't seem to be doing that.

Second, Excel is NOT unique among programming languages or
expression-driven numerical computation software in giving unary minus
higher operator precedence than exponentiation. That *IS* contrary to
the standard bodmas (the English acronym) math/science textbook
operator precedence, but Excel is highly idiosyncratic about which
standards it follows. FWLIW, Excel's operator precedence is the same as
COBOL and some SQL dialects. It has also been in place for decades now,
so changing it merely to suit purists' whims could break many existing
spreadsheet models.

Getting back to the similarity to COBOL, if Excel's original
programmers believed that most Excel users back in the mid 1980s would
have been more familiar with COBOL than math texts, their choice of
operator precedence would NOT have been a mistake, just an unfortunate
design decision. However, changing that operator precedence now would
be a MONUMENTAL MISTAKE for the reason already given: it'd screw up
millions if not billions of existing spreadsheets.

Besides, this has been discussed many times in the past. There's a much
longer thread in the comp.sci.math ng archives that goes into this in
much greater depth. Yes, Excel's operator precedence is unfortunate.
No, it's not unique. No, it probably wasn't a mistake. No, it's not
going to change in our lifetimes. So . . . get used to it.