# Complex number exponential function

Hello everyone,

I am new to CUDA programming.

I need to write a kernel function which has exponential operation on complex numbers. What is the right way to do this?

If A is float number, in kernel, I can use exp(A) or expf(A). But how to do on complex number?

If I do :
cuComplex a;
B = expf(a);

I will have error:
error: no suitable conversion function from “cuComplex” to “float” exists

Can anyone give me any advice? Thanks

cuComplex.h only provides complex types and basic complex arithmetic, intended to serve the needs of CUBLAS and other libraries. The complex exponential function can be computed component-wise in straightforward manner:

exp(z) = exp(x + iy) = exp(x) * exp (iy) = exp(x) * (cos(y) + i sin(y))

This then leads to code like this (untested):

``````__device__ __forceinline__ cuComplex my_cexpf (cuComplex z)

{

cuComplex res;

float t = expf (z.x);

sincosf (z.y, &res.y, &res.x);

res.x *= t;

res.y *= t;

return res;

}
``````

Thank you.