operator **

=?ISO-2022-JP?B?GyRCOGVGIyEhQDU8IxsoQg==?= (MXJ02154@niftyserve.or.jp)
Tue, 06 May 1997 22:25:00 +0900


ROOT users,

I propose following implementation to power operator ** and pow() function
in ROOT.

1: pow() function is a C function. So, ROOT/CINT calls it without checking.
Implementation of pow() function varies with system, so does the behavior
of pow() on ROOT. However, a user get consistent result between compiled
code and interpreted macro.

2: operator ** is a special extention to ROOT/CINT which does not exist
in standard C/C++. As discussed in 1, behavior of pow() depends on system.
Because ROOT is a platform independent environment, it is desirable that
operator ** behaves consistently among systems. ROOT/CINT implementation
will be changed as following. However, I do not recommend giving negative
operands to **. One reason is that operator precedence is not quite right.
You need to use () for negative numbers like '(-1.3)**4'.

a ** b

if( a > 0.0 ) {
use pow() or exp(b*log(a))
}
else if(a == 0.0) {
result is 0.0
}
else if(b is non-nagaive integral value) {
result = 1.0;
for(int i=0;i<b;i++) result *= a ;
}
else {
ERROR
return 0.0
}

Masaharu Goto