18 Nov
2004
18 Nov
'04
2:15 p.m.
Isidro CachadiƱa GutiƩrrez wrote:
cl_R x,y,z;
z=expt(x,y);
I have problems with the prototypes defined in <real.h> that causes that expt cannot be used in this way.
If x is negative, the result can be a complex number. If you know a priori that the result will be real, you can use a checked cast: z = As(cl_R)(expt(x,y));
I also can define this function as:
cln::cl_R expt(cln::cl_R x, cln::cl_R y) { return exp(x*ln(y)); }
Actually this is the other way around: exp(x*ln(y)) is y^x, not x^y. By using 'ln' here, not the more general 'log', you have asserted that the base is > 0. No wonder you don't need a cast here. Bruno