Blitz logo

Blitz Support :

From: Peter Kümmel (syntheticpp_at_[hidden])
Date: 2005-06-22 05:43:04


Julian Cummings wrote:
> What you need to do instead is multiply the Arrays represented by the
> placeholders x and y by the appropriate scalar constants. Instead of
> complex<double>(x,y), you would write
>
> complex<double>(1,0)*(1.0*x)+complex<double>(0,1)*(1.0*y)

This version is 10%-20% slower than a version generated with a
function/macro which takes 4 parameters. The new version is also
better to read.

The following example calculates A*exp(d*z) with the complex
number z=a+ib, and the distance d=sqrt(x*x+y*y).

old style:
A = A * exp(
complex<double>(1,0)*(a*sqrt(1.0*(pow2(x)+pow2(y)))) +
complex<double>(0,1)*(b*sqrt(1.0*(pow2(x)+pow2(y))))
);

new style:
A = exp_daib(A, sqrt(1.0*(pow2(x)+pow2(y))), a, b);

with
complex<double> exp_daib(complex<double> c, double d, double a, double b){
        return c*exp(complex<double>(d*a,d*b));
};

>>(I've here a BZ_DEFINE_TERNARY_FUNC_RET macro which I could
>>submit if you are intested)
> I'm not sure that such a beast is ever needed in practice.

Blitz is a library, who knows what the client want to do with it.

> Can you give an
> example of a ternary math functor that you want to apply to Arrays?

Maybe exp_daib is an example. One could cut it down to two arguments, but
then one have to set a and b somewhere else.

Best regards,
Peter