jcuda
Class cuComplex

java.lang.Object
  extended by jcuda.cuComplex

public class cuComplex
extends java.lang.Object

Java port of the CUDA complex number structure.


Field Summary
 float x
          The real part of the complex number
 float y
          The imaginary part of the complex number
 
Method Summary
static float cuCabs(cuComplex x)
          Returns the absolute value of the given complex number.
static cuComplex cuCadd(cuComplex x, cuComplex y)
          Returns a new complex number that is the sum of the given complex numbers.
static cuComplex cuCdiv(cuComplex x, cuComplex y)
          Returns the quotient of the given complex numbers.
static float cuCimag(cuComplex x)
          Returns the imaginary part of the given complex number.
static cuComplex cuCmplx(float r, float i)
          Creates a new complex number consisting of the given real and imaginary part.
static cuComplex cuCmul(cuComplex x, cuComplex y)
          Returns the product of the given complex numbers.
static cuComplex cuConj(cuComplex x)
          Returns the complex conjugate of the given complex number.
static float cuCreal(cuComplex x)
          Returns the real part of the given complex number.
 java.lang.String toString()
          Returns a String representation of this complex number.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public float x
The real part of the complex number


y

public float y
The imaginary part of the complex number

Method Detail

cuCreal

public static float cuCreal(cuComplex x)
Returns the real part of the given complex number.

Parameters:
x - The complex number whose real part should be returned
Returns:
The real part of the given complex number

cuCimag

public static float cuCimag(cuComplex x)
Returns the imaginary part of the given complex number.

Parameters:
x - The complex number whose imaginary part should be returned
Returns:
The imaginary part of the given complex number

cuCmplx

public static cuComplex cuCmplx(float r,
                                float i)
Creates a new complex number consisting of the given real and imaginary part.

Parameters:
r - The real part of the complex number
i - The imaginary part of the complex number
Returns:
A complex number with the given real and imaginary part

cuConj

public static cuComplex cuConj(cuComplex x)
Returns the complex conjugate of the given complex number.

Parameters:
x - The complex number whose complex conjugate should be returned
Returns:
The complex conjugate of the given complex number

cuCadd

public static cuComplex cuCadd(cuComplex x,
                               cuComplex y)
Returns a new complex number that is the sum of the given complex numbers.

Parameters:
x - The first addend
y - The second addend
Returns:
The sum of the given addends

cuCmul

public static cuComplex cuCmul(cuComplex x,
                               cuComplex y)
Returns the product of the given complex numbers.

Original comment:

This implementation could suffer from intermediate overflow even though the final result would be in range. However, various implementations do not guard against this (presumably to avoid losing performance), so we don't do it either to stay competitive.

Parameters:
x - The first factor
y - The second factor
Returns:
The product of the given factors

cuCdiv

public static cuComplex cuCdiv(cuComplex x,
                               cuComplex y)
Returns the quotient of the given complex numbers.

Original comment:

This implementation guards against intermediate underflow and overflow by scaling. Such guarded implementations are usually the default for complex library implementations, with some also offering an unguarded, faster version.

Parameters:
x - The dividend
y - The divisor
Returns:
The quotient of the given complex numbers

cuCabs

public static float cuCabs(cuComplex x)
Returns the absolute value of the given complex number.

Original comment:

This implementation guards against intermediate underflow and overflow by scaling. Otherwise the we'd lose half the exponent range. There are various ways of doing guarded computation. For now chose the simplest and fastest solution, however this may suffer from inaccuracies if sqrt and division are not IEEE compliant.

Parameters:
x - The complex number whose absolute value should be returned
Returns:
The absolute value of the given complex number

toString

public java.lang.String toString()
Returns a String representation of this complex number.

Overrides:
toString in class java.lang.Object
Returns:
A String representation of this complex number