Вопрос

Lets say we have the following constructor..

 complex(int,x,int,y){
 r = x;
 i = y;
 }

If I was to take 3*complex(1,2) is that essentially the same thing as multiplying

complex(1,2)*complex(3,0)?

I'm trying to calculate a julia set here, and am very new to complex numbers. Thanks for any help!

Это было полезно?

Решение

Yes, but the way you're writing it doesn't match C or C++, or CUDA.

If you have a complex number (2-6i) and you want to multiply it by 3, that is the same as multiplying it by (3+0i).

If you want to use complex numbers in CUDA, I would save yourself some trouble and start with all the definitions to be had when you do:

#include <cuComplex.h>

(on a standard linux CUDA install this would be in /usr/local/cuda/include)

Use it in any .cu file you compile with nvcc. where you need to use complex numbers.

If you familiarize yourself with that header file, you'll save yourself some time trying to build these things by hand.

There are functions to build complex numbers, and do various types of arithmetic on them. You can also search here on SO for more advanced functions, like polar conversion, etc.

And the wikipedia article makes a good read too.

Here's sample code to multiply (2-6i) * (3+0i):

cuDoubleComplex a, b, c;
a = make_cuDoubleComplex(2, -6);
b = make_cuDoubleComplex(3,  0);
c = cuCmul(a, b);

The above code works equally well in host code or device code.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top