Re: Order of operations (was: Eigenvalues &/or eigenvectors, anyone?)
Re: Order of operations (was: Eigenvalues &/or eigenvectors, anyone?)
- Subject: Re: Order of operations (was: Eigenvalues &/or eigenvectors, anyone?)
- From: Michael Kelly <email@hidden>
- Date: Fri, 9 May 2003 10:46:28 -0700
- Mail-followup-to: AppleScript-Users <email@hidden>
On Thu, May 08, 2003 at 06:50:43PM -0400, Deivy Petrescu wrote:
>
Another thing, I did not try perl, but you can include python in the
>
ones that use -2^2=-4.
>
bc uses the same notation that A, -2^2=4
>
A calculator does the same thing..
A calculator does this because it must be explicitly dictated by the
user that a unary minus is what's being used, as mentioned elsewhere in
this thread, with the +/- key. In cases where all you have is a "-"
character in front of a number (as with programming languages), it's
ambiguous, because "-" can mean different things. (And, in the case of
AS, those different meanings carry with them difference precedences,
which is mostly what I'm complaining about.)
>
In order to avoid problems, to be certain, I'd always insert
>
parenthesis in the expression.
>
>
I would call it a bug. I still feel that the canonical way is -2^2=4,
>
nothing wrong with (-2)^2=4.
Agreed that parentheses should always be used to resolve ambiguities
like this.
I suppose it all boils down to a debate about whether, when it is
ambiguous, a - should be considered a unary minus or a subtraction. I
personally feel the unary minus should not be used unless it is
necessary, as in 10 * -2, where you have no choice.
If - is subtraction until proven otherwise, it makes perfect sense for
-2^2 = -4. If it is a unary minus until proven otherwise, it's logical
for -2^2 = 4, _if_ it is accepted that the unary minus has higher
precedence than the exponentiation operator, which it isn't.
I again bring up the example of Perl. Unary minus has higher precedence
than multiplication and addition, which allows things like 2 - -2 and
10 * -2 to work, but lower than ** (exponentiation, equivalent to ^ in
AS). I feel this is good because it resolves the problem before it
exists. Regardless of whether the - in -2^2 is a unary minus or a
binary subtraction with an implicit 0, the result is the same, because
both operators have lower precedence than ^.
But this is surely another one of those debates that'll never go
anywhere. I haven't seen anyone convince anyone else of the error of
their ways. :)
Regardless of my opinion, this discussion has been very interesting and
enlightening, for me,
--
Michael
email@hidden
http://www.jedimike.net
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.