[CLN-list] Types in cl_R

Bruno Haible bruno at clisp.org
Thu Nov 18 13:15:04 CET 2004


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





More information about the CLN-list mailing list