Re: math operators

new topic     » goto parent     » topic index » view thread      » older message » newer message

Pete wrote:

> On Sat, 20 Sep 2003 16:50:39 +0200, Juergen Luethje <j.lue at gmx.de>
> wrote:
>
>> And how about the power operator? What is the result of
>>    2^3^2  ?
>>
>> Mathematically, evaluation is right to left for the power operator! So
>>    2^3^2 = 2^(3^2) = 2^9 = 512.
>>
>> But there seems to be a kind of "industry standard", that says that such
>> expressions should be calculated from left to right. That means:
>>    2^3^2 = (2^3)^2 = 8^2 = 64
>
> When I wrote the expression evaluator for my report generator, I snuck
> ^ in and found EXACTLY that example!

smile

> After thinking about it a while,
> I made the operator non-associative so if you key that expression it
> complains "ambiguous: add parenthesis".

Very nice! That's the best choice in that situation IMHO.

<snip>

> As an aside, I based my expression evaluator on a paper by Thomas
> Niemann (http://epaperpress.com/oper/index.html) which, as the author
> admits, has some unusual effects: All of the following evaluate to 25:
>             power 5 2
>             power() 5 2
>             power(5) 2
>             power(5,2)
>             5 power 2
>             5 power() 2
>             5 power(2)
>             5 2 power()
>             ^ 5 2
>             5^2
>             5 2 ^

LOL! Unusual indeed. smile

<snip>

Regards,
   Juergen

-- 
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x].

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu