jjil.core
Class Complex

java.lang.Object
  extended by jjil.core.Complex

public class Complex
extends java.lang.Object

A simple implementation of complex numbers for use in FFT, etc.

Author:
webb

Constructor Summary
Complex()
          Default constructor.
Complex(Complex cx)
          Copy constructor.
Complex(int nReal)
          Create a new Complex number from a real number.
Complex(int nReal, int nImag)
          Creates a new instance of Complex from real and imaginary arguments.
 
Method Summary
 Complex conjugate()
          Complex conjugate
 Complex div(Complex cx)
          Divides one complex number by another
 Complex div(int n)
          Divide the complex number by a real ineger.
 boolean equals(Complex cx)
          Equality test.
 int imag()
          The imaginary component of the complex number.
 Complex lsh(int n)
          Shifts a complex number left a certain number of bits.
 int magnitude()
          Complex magnitude.
 Complex minus(Complex cx)
          Subtracts one complex number from another.
 Complex plus(Complex cx)
          Adds two complex numbers.
 int real()
          The real component of the complex number.
 Complex rsh(int n)
          Shifts a complex number right a certain number of bits.
 int square()
          Computes the absolute square.
 Complex times(Complex cx)
          Multiplies two complex numbers.
 Complex times(int nX)
          Multiplies a complex number by a real number.
 java.lang.String toString()
          Returns a String representation of the complex number
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Complex

public Complex()
Default constructor.


Complex

public Complex(Complex cx)
Copy constructor.

Parameters:
cx - the complex number to copy.

Complex

public Complex(int nReal,
               int nImag)
Creates a new instance of Complex from real and imaginary arguments.

Parameters:
nReal - Real component.
nImag - Imaginary component.

Complex

public Complex(int nReal)
Create a new Complex number from a real number. The imaginary component will be 0.

Parameters:
nReal - The real component.
Method Detail

conjugate

public Complex conjugate()
Complex conjugate

Returns:
the complex conjugate of this.

div

public Complex div(int n)
            throws Error
Divide the complex number by a real ineger.

Parameters:
n - the divisor.
Returns:
the Complex number resulting from the division (replaces this).
Throws:
Error - if n = 0

div

public Complex div(Complex cx)
            throws Error
Divides one complex number by another

Parameters:
cx - The complex number to divide by.
Returns:
the result of dividing this number by cx.
Throws:
Error - If division by 0 is attempted, i.e., cx.square() is 0.

equals

public boolean equals(Complex cx)
Equality test.

Parameters:
cx - the Complex number to compare with.
Returns:
true iff the two Complex numbers are equal.

imag

public int imag()
The imaginary component of the complex number.

Returns:
the imaginary component.

lsh

public Complex lsh(int n)
Shifts a complex number left a certain number of bits.

Parameters:
n - The number of bits to shift by.
Returns:
the result of shifting the complex number left the number of bits.

magnitude

public int magnitude()
              throws Error
Complex magnitude.

Returns:
the magnitude of this number, i.e., sqrt(real**2 + imag**2)
Throws:
Error - if the square value computed is too large.

minus

public Complex minus(Complex cx)
Subtracts one complex number from another.

Parameters:
cx - the complex number to subtract.
Returns:
the difference of the two complex numbers.

plus

public Complex plus(Complex cx)
Adds two complex numbers.

Parameters:
cx - the complex number to add.
Returns:
the sum of the two complex numbers.

real

public int real()
The real component of the complex number.

Returns:
the real component of the complex number.

rsh

public Complex rsh(int n)
Shifts a complex number right a certain number of bits.

Parameters:
n - The number of bits to shift by.
Returns:
the result of shifting the complex number the number of bits.

square

public int square()
           throws Error
Computes the absolute square.

Returns:
The absolute square, i.e, real**2 + imag**2.
Throws:
Error - if Complex value is too large.

times

public Complex times(Complex cx)
Multiplies two complex numbers.

Parameters:
cx - The complex number to multiply by.
Returns:
The product of the two numbers.

times

public Complex times(int nX)
Multiplies a complex number by a real number.

Parameters:
nX - The complex number to multiply by.
Returns:
The product of the two numbers.

toString

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

Overrides:
toString in class java.lang.Object
Returns:
the string (real, imag)