emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calc: `*' binds more strongly than `/'


From: Christian Schlauer
Subject: Re: Calc: `*' binds more strongly than `/'
Date: Wed, 25 Apr 2007 21:56:51 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.98 (gnu/linux)

Jay Belanger <address@hidden> writes:

> address@hidden (Kim F. Storm) writes:
> ...
>> I seem to be the only one who have spoken in favour of the current
>> precedence rule, but I'm only a casual user of calc, so my opinion
>> shouldn't matter here!
>
> You must have missed a few messages; you are by no means the only one
> in favor of the current rule.

I checked the thread and Randal L. Schwartz, Daniel Brockman and Kim
F. Storm backed up the current behaviour. Carsten Dominik likes the
current behaviour, too.

Stefan Monnier, Miles Bader, Jason Rumney and me "prefer" a change of
the current behaviour.

>> Besides, I usually add () to mixtures of / and * anyway (for clarity
>> and/or to dictate a specific evaluation order to get maximum precision
>> in the result).
>
> Well, I think that's the proper way of doing it; even though there are
> rules for interpreting expressions like a*b/c*d, that doesn't mean
> writing the expression that way is a good thing to do -- it's just bad
> form.  I don't think there is any difference between Calc's current
> precedence rule and the more standard one for properly written
> expressions.

I did some more `research', and a*b/c*d is not bad form, and it is a
properly written expression, see Wikipedia. Let me cite from
<http://en.wikipedia.org/wiki/Order_of_operations#Examples_from_arithmetic>:

,----
| 3. Evaluate multiplications and divisions, starting from the left:
| 
| 8/2*3 = [8/2]*3 = [4*3] = 12
`----

Further down on the same page:

"Since multiplication and division are of the same rank, [...]"

and further on (emphasis added by me):

,----
| Warning: Multiplication and division are of *equal precedence*, and
| addition and subtraction are of *equal precedence*. Using any of the
| above rules in the order addition first, subtraction afterward would
| give the wrong answer to
| 
| 10 - 3 + 2
| 
| The correct answer is 9, which is best understood by thinking of the
| problem as the sum of positive ten, negative three, and positive
| two.
| 
| It is usual, wherever you need to calculate operations of equal
| precedence to work *from left to right*. The following rules of
| thumb are useful:
| 
| First: perfom any calculations inside parentheses (brackets)
| 
| Second: Next perform all multiplication and division, working from
| *left to right*
| 
| Third: Lastly perform all addition and subtraction, working from
| *left to right*
`----

So besides Excel, Gnumeric, MATLAB, all pocket calculators, Wikipedia
agrees with me, too.

Calc's current behaviour is simply wrong, I'd say.

Regards,

Christian

P.S.: I have not edited the Wikipedia article.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]