I know that OpenCL doesn’t have support for complex numbers, and by what I’ve read this feature isn’t going to show up anytime soon.
Still, several examples make use of complex numbers in OpenCL kernels (FFT implementations for instance).
Does anybody have experience with this? What would be the “best” method to enable complex number support in OpenCL? I’d assume using a float2 to contain the real and imaginary parts, but should I write a set of macros, or are inline functions better? Does anybody know if a set of functions/macros already exists for this purpose?
So, as I needed a set of functions to handle complex numbers in OpenCL I ended up implementing a set of them. Specifically i needed sum and subtraction (trivial, can be done with standard vector operations), multiplication, division, getting a complex’s modulus, argument (or angle) and square root.
relevant wikipedia articles:
http://en.wikipedia.org/wiki/Complex_number#Absolute_value_and_argument
http://en.wikipedia.org/wiki/Square_root#Principal_square_root_of_a_complex_number
This is mostly trivial, but it does take some time, so in the hope in might save someone this time, here goes: