[Kst] Equation parser - a possible BUG.
Barth Netterfield
netterfield at astro.utoronto.ca
Mon Nov 22 15:14:11 CET 2004
All references agree that -x^2 = (-1)*x^2. (or equivalently, -x^2 = 0 - x^2).
The following page notes also that some software packages get it right, and
some get it wrong. for example, bc and MS-excel do it wrong (!) but MSworks
spreadsheet gets it right (!!)
http://www.macnauchtan.com/pub/precedence.html
I also have read that exponentiation is *right* associative so bc is correct
in this one.
So I'm pretty sure that the rules below for the patch are correct.
I would commit asap, to give a little more chance for us to also look for
crashes.
cbn
On November 21, 2004 11:55 pm, George Staikos wrote:
> I just compared against bc(1) and it seems to behave different than you
> describe, and different than we currently do. Therefore I wrote some
> testcases which we can use to try to more precisely define what we want.
> We had operator ^ behaving like this:
>
> -x^y evaluates as: (-x)^y
> x^y^z evaluates as: (x^y)^z
>
> bc(1) has:
> -x^y evaluates as: (-x)^y <------- same as we do
> x^y^z evaluates as: x^(y^z) <---- different
>
> This patch changes us to evaluate like this:
> -x^y evaluates as: -(x^y)
> x^y^z evaluates as: x^(y^z)
>
> Now I'm not convinced that it's a good idea since it does the opposite of
> bc(1). Can you test against other apps? What do they do?
>
> Barth/Andrew: What do you think? Should this patch go in? If so, I won't
> commit yet, but I will continue to write testcases tomorrow. Then I can
> commit tomorrow night if no other issues pop up.
>
> > Hope helping improving the KST quality,
>
> Thanks!
More information about the Kst
mailing list