Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,sci.math
external usenet poster
 
Posts: 733
Default Excel Math Bug

Phil Carmody wrote...
....
He probably means that unary minus has a significantly higher

precedence
than subtraction, so much so that it has a strictly higher precedence
than at least one operator that one would commonly view as being of a
strictly higher precdence than subtraction.


No kidding! Gee, I'd never have guessed. How odd that this makes C
just like FORTRAN. I've been involved in a few back & forth
discussions with Alan, and I have little doubt he misconstrued C's ^
operator.

FWLIW, the precedence of unary minus/negation and multiplication,
division and remainder operators just doesn't matter. Considering C's
*,

(a * b) == (-a) * (-b) == -(a * (-b))
(-a * b) == (-a) * b == -(a * b)
(a * -b) == a * (-b) [b's - can't be parsed otherwise]
(-a * -b) == (-a) * (-b) == (-a * (-b)) == -(a * (-b))

Unary minus *could* have been given equal to or lower precedence than
*, / and %, and it wouldn't have mattered. I suspect the reason it's
higher is that it was supposed to be given the same as -- and ++, and
those are given higher precedence than *, / and %. Much, much easier
giving all unary operators the same precedence, so they'd be resolved
by the associativity rule alone.

Therefore there is a concrete example of an expression which is

interpretted
differently in C than it would be using people like you's

conventions.

First, what are my conventions? Second, if my favored conventions
exactly matched those of Excel, how would that matter vis-a-vis
negation/unary minus and *, / or %? While the machine may mechanically
parse unary minus earlier than *, / or %, the results would be the
same if it parsed unary minus after.

In C's case, the precedence inversion is with the multiplicative

family
of operators. e.g. compare C's interpretation of -2%3 as (-2)%3

rather than
-(2%3).


OK, it matters for remainder, but because there's residual ambiguity
about what (-2) % 3 should return. Is the answer -2 or +1? This is
also a matter of convention, and there are differences of opinion.
FWIW, C and Excel differ here, but it's due to the sign convention of
the remainder operator, not to operator precedence. In C, -2 % 3 ==
(-2) % 3 == -(2 % 3) == -2, but in Excel MOD(-2,3) == 1 != or <
-MOD(2,3) == -2. Note that because Excel uses a function for
remainder, unary minus's operator precedence is immaterial; the signs
of both arguments to the remainder function are necessarily obvious.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Less Excel more Math Ty Excel Worksheet Functions 1 April 16th 11 06:28 AM
Math functions in Excel Farhad Excel Discussion (Misc queries) 2 February 19th 07 04:16 PM
Excel math formula dan Excel Worksheet Functions 4 October 30th 06 04:51 PM
How do I ? math/excel question Madduck Excel Discussion (Misc queries) 3 July 26th 06 05:41 AM
More math than excel, but a fun problem S Davis Excel Worksheet Functions 4 July 6th 06 10:04 PM


All times are GMT +1. The time now is 05:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"