Re: math operators

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

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 =3D 2^(3^2) =3D 2^9 =3D 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 =3D (2^3)^2 =3D 8^2 =3D 64

When I wrote the expression evaluator for my report generator, I snuck
^ in and found EXACTLY that example!  After thinking about it a while,
I made the operator non-associative so if you key that expression it
complains "ambiguous: add parenthesis".

>>> BITWISE OPERATORs
>>> compare() become =3D=3D
>>> and_bits() become &&
>>> or_bits() become ||
>>>
>>> or at least see them used as operators. Such as:
>>>   if (int1 and_bits int2) then
>>>     if (int2 or_bits int2) then
>>>     end if
>>>   end if
>>> But that wouldn't be backwards compatible. :(
>>
>> again, yes!
>
>No, please!
>I'm happy that Euphoria code is very good readable ATM.
>I would not be happy to see anything that makes it less readable.

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 ^

If anyone is interested, I'll clean it up and post it. Maybe someone
with a fresh perspective can fix that for me.

I also support and_bits and or_bits, which can also be written infix.

Elliot wrote:
>(For those who thought ^ was power, it really is bitwise XOR.)

Yes, you're probably right. I think I'll remove the ^ operator.

Regards,
Pete

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

Search



Quick Links

User menu

Not signed in.

Misc Menu