jfftw
Class Complex

java.lang.Object
  extended by jfftw.Complex
All Implemented Interfaces:
Cloneable

public class Complex
extends Object
implements Cloneable

Class to handle Complex numbers and arithmetic. The complex is held a two double, and all arithmetic is in double format. Much of the internal coding does not use methods for efficiency reasons.


Field Summary
static int BOTH
          Static to specify both parts of a Complex number
 double i
          The imaginary part
static int IMAG
          Static to specify imaginary part of Complex number
static int LOG_POWER
          Static to specify Log Power of a Complex
static int MODULUS
          Static to specify the modulus of a Complex number
static int MODULUS_SQUARED
          Static to specify the modulus squared of a Complex number
static int PHASE
          Static to specify the phase of a Complex number
 double r
          The real part
static int REAL
          Static to specify real part of Complex number
 
Constructor Summary
Complex()
          Default constructor for Complex with both real and imaginary zero
Complex(Complex c)
          Constructor for Complex with Complex parameter
Complex(double a)
          Constructor for Complex with real part only
Complex(double a, double b)
          Constructor for Complex with two doubles
 
Method Summary
static Complex add(Complex a, Complex b)
          Static add method with two parameters
 void addTo(Complex c)
          Method to add to the current Complex
 void addTo(double r, double i)
          Void method to add to the current Complex
 Complex clone()
          Method to clone the current Complex
 Complex conj()
          The Complex conjugate of the current Complex
 Complex from(Complex c)
          Subtract the current Complex FROM specified value returning a new Complex
 Complex from(double a)
          Subtract the current Complex from a scalar returning a new Complex
 Complex from(double a, double b)
          Subtract the current Complex FROM specified value retuning a new Complex
 double getDouble(int flag)
          Method to get double, converted from current Complex as specified by the conversion flag.
 double getImag()
          Get the imag part
 double getReal()
          Get the real part
 boolean isNaN()
          Test of either components set to NaN
 double logPower()
          Get the log power, being defines at log(r*r + i*i + 1.0)
 Complex minus(Complex c)
          Subtract a complex from the current retuning a new Complex
 Complex minus(double a)
          Subtract a real number from the current retuning a new Complex
 Complex minus(double a, double b)
          Subtract a complex from the current returning a new Complex
 double modulus()
          Get the modulus of the Complex
 double modulusSq()
          Get the modulus squared of the Complex
 Complex mult(Complex c)
          Multiply the current by a specified Complex, returning a new Complex.
static Complex mult(Complex a, Complex b)
          Static mult method with two parameters
 Complex mult(double a)
          Multiply the current by a scalar returning a new Complex
 Complex mult(double a, double b)
          Multiply the current by a specified Complex, returning a new Complex.
 void multBy(Complex c)
          Method to mult the current Complex by specified Complex
 void multBy(double a)
          Method to mult the current Complex by specified real
 void multBy(double a, double b)
          Method to mult the current Complex by specified Complex
 Complex multConj(Complex c)
          Multiply the current by the conjugate of the specified Complex retuning a new Complex
 Complex over(Complex c)
          Divide the current by specified Complex returning new Complex
 Complex over(double a)
          Divide the current Complex by a scalar returning a new Complex
 Complex over(double a, double b)
          Divide the current by specified Complex returning new Complex
 double phase()
          Get the phase from atan2(i,r) method.
 Complex plus(Complex c)
          Add a complex to the current returning a new Complex.
 Complex plus(double a)
          Add a real number to the current returning a new Complex.
 Complex plus(double a, double b)
          Add a complex to the current returning a new Complex
 Complex scale(double mod)
          Form a scaled Complex from the current Complex with specified modulus, while retaining phase.
 void set(Complex c)
          Method to reset the Complex value
 void set(double a, double b)
          Method reset Complex value
 void setExpi(double theta)
          Method to set Complex value to expi(theta)
 void setFormatString(String fmt)
          Change the default format, by default set to "%g"
 void setImag(double b)
          Set the imaginary part, real part unchanged
 void setInvalid()
          Method to set the current Complex to be invalid, with both real and imaginary set to NaN
 void setPolar(double rho, double theta)
          Method to set the Complex value with polar parameters
 void setRandomPhase(double m)
          Method to set a Complex to a specified modulus, but the phase set randomly between 0 to 2pi
 void setReal(double a)
          Set the real part, imaginary part unchanged
 String toString()
          Format the current Complex as a String
 Complex under(Complex c)
          Divide the specified Complex BY the current Complex
 Complex under(double a)
          Divide the specified scalar BY the current Complex returning a new Complex
 Complex unity()
          Form a unit modulus version current Complex retaining the phase
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REAL

public static final int REAL
Static to specify real part of Complex number

See Also:
Constant Field Values

IMAG

public static final int IMAG
Static to specify imaginary part of Complex number

See Also:
Constant Field Values

BOTH

public static final int BOTH
Static to specify both parts of a Complex number

See Also:
Constant Field Values

MODULUS

public static final int MODULUS
Static to specify the modulus of a Complex number

See Also:
Constant Field Values

PHASE

public static final int PHASE
Static to specify the phase of a Complex number

See Also:
Constant Field Values

MODULUS_SQUARED

public static final int MODULUS_SQUARED
Static to specify the modulus squared of a Complex number

See Also:
Constant Field Values

LOG_POWER

public static final int LOG_POWER
Static to specify Log Power of a Complex

See Also:
Constant Field Values

r

public double r
The real part


i

public double i
The imaginary part

Constructor Detail

Complex

public Complex(double a,
               double b)
Constructor for Complex with two doubles

Parameters:
a - real part
b - imaginary part

Complex

public Complex(double a)
Constructor for Complex with real part only

Parameters:
a - real part

Complex

public Complex()
Default constructor for Complex with both real and imaginary zero


Complex

public Complex(Complex c)
Constructor for Complex with Complex parameter

Parameters:
c - the Complex value
Method Detail

clone

public Complex clone()
Method to clone the current Complex

Overrides:
clone in class Object
Returns:
Complex clone of the current Complex

set

public void set(double a,
                double b)
Method reset Complex value

Parameters:
a - the real part
b - the imaginary value

set

public void set(Complex c)
Method to reset the Complex value

Parameters:
c - the Complex value

setPolar

public void setPolar(double rho,
                     double theta)
Method to set the Complex value with polar parameters

Parameters:
rho - the radial parameter
theta - the angular parameter

setExpi

public void setExpi(double theta)
Method to set Complex value to expi(theta)

Parameters:
theta - the angular parameter

setRandomPhase

public void setRandomPhase(double m)
Method to set a Complex to a specified modulus, but the phase set randomly between 0 to 2pi

Parameters:
m - the modulus

setInvalid

public void setInvalid()
Method to set the current Complex to be invalid, with both real and imaginary set to NaN


isNaN

public boolean isNaN()
Test of either components set to NaN

Returns:
boolean true if NaN]

setReal

public void setReal(double a)
Set the real part, imaginary part unchanged

Parameters:
a - the real value

setImag

public void setImag(double b)
Set the imaginary part, real part unchanged

Parameters:
b - the imaginary part

getReal

public double getReal()
Get the real part

Returns:
double the real part

getImag

public double getImag()
Get the imag part

Returns:
double the imaginary part

modulusSq

public double modulusSq()
Get the modulus squared of the Complex

Returns:
double the modulus squared

modulus

public double modulus()
Get the modulus of the Complex

Returns:
double the modulus

phase

public double phase()
Get the phase from atan2(i,r) method.

Returns:
double the phase in range -pi -> pi

logPower

public double logPower()
Get the log power, being defines at log(r*r + i*i + 1.0)

Returns:
double the log power

getDouble

public double getDouble(int flag)
Method to get double, converted from current Complex as specified by the conversion flag.

Parameters:
flag - the conversion flag

plus

public Complex plus(Complex c)
Add a complex to the current returning a new Complex.

Parameters:
c - the complex
Returns:
Complex the sum

plus

public Complex plus(double a,
                    double b)
Add a complex to the current returning a new Complex

Parameters:
a - the real part
b - the imaginary part
Returns:
Complex the sum

plus

public Complex plus(double a)
Add a real number to the current returning a new Complex.

Parameters:
a - the real part
Returns:
Complex the sum

minus

public Complex minus(Complex c)
Subtract a complex from the current retuning a new Complex

Parameters:
c - the complex
Returns:
Complex the result

minus

public Complex minus(double a,
                     double b)
Subtract a complex from the current returning a new Complex

Parameters:
a - the real part
b - the imaginary part
Returns:
Complex the result

minus

public Complex minus(double a)
Subtract a real number from the current retuning a new Complex

Parameters:
a - the real part
Returns:
Complex the result

from

public Complex from(Complex c)
Subtract the current Complex FROM specified value returning a new Complex

Parameters:
c - the complex
Returns:
Complex the result

from

public Complex from(double a,
                    double b)
Subtract the current Complex FROM specified value retuning a new Complex

Parameters:
a - the real part
b - the imaginary part
Returns:
Complex the result

from

public Complex from(double a)
Subtract the current Complex from a scalar returning a new Complex

Parameters:
a - the real part
Returns:
Complex the result

mult

public Complex mult(double a)
Multiply the current by a scalar returning a new Complex

Parameters:
a - the scalar
Returns:
Complex the multiplication

mult

public Complex mult(double a,
                    double b)
Multiply the current by a specified Complex, returning a new Complex.

Parameters:
a - the real part
b - the imaginary part
Returns:
Complex the multiplication

mult

public Complex mult(Complex c)
Multiply the current by a specified Complex, returning a new Complex.

Parameters:
c - the Complex
Returns:
Complex the multiplication

multConj

public Complex multConj(Complex c)
Multiply the current by the conjugate of the specified Complex retuning a new Complex

Parameters:
c - the Complex
Returns:
Complex the multiplication

over

public Complex over(double a)
Divide the current Complex by a scalar returning a new Complex

Parameters:
a - the scalar
Returns:
Complex the result

over

public Complex over(double a,
                    double b)
Divide the current by specified Complex returning new Complex

Parameters:
a - the real part
b - the imaginary part
Returns:
Complex the result

over

public Complex over(Complex c)
Divide the current by specified Complex returning new Complex

Parameters:
c - the Complex
Returns:
Complex the result

under

public Complex under(double a)
Divide the specified scalar BY the current Complex returning a new Complex

Parameters:
a - the scalar
Returns:
Complex The result

under

public Complex under(Complex c)
Divide the specified Complex BY the current Complex

Parameters:
c - the Complex
Returns:
Complex The result

conj

public Complex conj()
The Complex conjugate of the current Complex

Returns:
Complex the conjugate

unity

public Complex unity()
Form a unit modulus version current Complex retaining the phase

Returns:
Complex Unit modulus Complex

scale

public Complex scale(double mod)
Form a scaled Complex from the current Complex with specified modulus, while retaining phase.

Parameters:
mod - the specified modulus
Returns:
Complex the scaled Complex.

toString

public String toString()
Format the current Complex as a String

Overrides:
toString in class Object
Returns:
String formatted Complex

setFormatString

public void setFormatString(String fmt)
Change the default format, by default set to "%g"

Parameters:
fmt - the new format String

addTo

public void addTo(Complex c)
Method to add to the current Complex

Parameters:
c - the Complex to be added

addTo

public void addTo(double r,
                  double i)
Void method to add to the current Complex

Parameters:
r - real part to be added
i - imaginary part of be added

multBy

public void multBy(double a,
                   double b)
Method to mult the current Complex by specified Complex

Parameters:
a - real part
b - imaginary part

multBy

public void multBy(Complex c)
Method to mult the current Complex by specified Complex

Parameters:
c - the specified Complex

multBy

public void multBy(double a)
Method to mult the current Complex by specified real

Parameters:
a - the multiplier

add

public static Complex add(Complex a,
                          Complex b)
Static add method with two parameters

Parameters:
a - first Complex
b - second Complex
Returns:
Complex the addition

mult

public static Complex mult(Complex a,
                           Complex b)
Static mult method with two parameters

Parameters:
a - first Complex
b - second Complex
Returns:
Complex the multiplication