Re: [ROOT] exponentiation

From: Bob McElrath (mcelrath@draal.physics.wisc.edu)
Date: Sat Sep 29 2001 - 02:47:23 MEST


Masaharu Goto [MXJ02154@nifty.ne.jp] wrote:
> Hello Bob,
> 
> I am glad you brought up this issue. 
> 
> Power operator is Cint's original enhancement. It is implemented
> in 2 ways, '**' and '@'.  Both 2**3 and 2@3 yield 8. 

Strictly, I believe the '@' symbol is a legal identifier symbol.  I have
seen code which uses it, though it is rare.  This program:
    int main() {
        int a@var = 1;
        return a@var;
    }
compiles and runs fine with gcc.  (though like numbers the '@' cannot be
used as the first character of an identifier)

> I originally made Cint in order to replace BASIC programming 
> environment when I did engineering work. In that field, power
> operator is a 'must' items to have.  I knew '**' causes problem
> in C/C++ in strict sense, but I saw more benefit than problem.

C/C++ has a power operator: pow(x,y).  Okay, so it's not an operator... :(
But it does work within root.

> But, I understand your point. I'll try to provide an option to
> disable ** operator with a compile flag.

Well, with the goal for Cint programs to be compilable, this is very
dangerous.  It means that compiled code containing a ** or @ will behave
differently than interpreted code, or simply not compile.

It is unfortunate that C++ did not include an exponentiation operator.
I find it ugly in my code to use pow(x, 2.0) rather than x^2 or x**2.
But I think it's too late to reverse that decision without unfortunate
consequences.

I hope you will consider removing it.  How widely used is this feature
anyway?

Cheers,
-- Bob

Bob McElrath (rsmcelrath@students.wisc.edu) 
Univ. of Wisconsin at Madison, Department of Physics





This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:01 MET