View Single Post
  #15   Report Post  
Old May 9th 09, 09:40 AM posted to rec.radio.amateur.antenna
Owen Duffy Owen Duffy is offline
external usenet poster
 
First recorded activity by RadioBanter: Dec 2006
Posts: 1,169
Default Be careful when using Excel

"Antonio Vernucci" wrote in
:

Do you realise that the '-' in both expressions are quite different
in meaning, one is a unary negation operator, the other is the binary
subract operator.


I realise, but Microsoft apparently does not:

- for Excel: (-2^2 + 8) = 12
- for Visual Basic: (-2^2 + 8) = 4

They look pretty much the same

Not to a programmer!


I would expect that some programmers may get confused, due to the
inconsistency of software products of the same company.


Do not assume that all languages or all products use the same operator
precedence rules.

The Excel rules are spelled out in the Excel help.

The key thing is that there is a difference in the meaning of '-' in the
uses as the negation operator and subtraction operator, same symbol, two
meanings, you need to understand that when looking in the list of
operator precedence.

Excel spells out clearly that unary negation has higher precedence than
exponentiation, and subtraction is lower than both... so keep that in
mind when writing formulae.

If you are writing VB, use the precedence rules for VB. The VB rules
clearly state that exponentiation has higher precedence than negation,
and subtraction is lower. This may have its roots before the existence of
Microsoft.

Many languages do not have an exponentiation operator, requiring
functions instead (often pow()). Such use eliminates the operator
precedence issue.

PERL does have an exponentiation operator, and it is higher precedence
than unary + and -.

FORTRAN90 does have an exponentiation operator, and it is higher
precedence than unary + and -.

It is part of the programming landscape... algebraic expressions are not
universal, they need to be written for the specific language.

Now, I hear that you think that is a bad idea, but it isn't likely to
change. It is most unlikely that a new version of any language will
change operator precedence, it has too many issues.

Owen