at.dms.kjc.sir.statespace
Class ComplexNumber

java.lang.Object
  extended by at.dms.kjc.sir.statespace.ComplexNumber

public class ComplexNumber
extends Object

This class represents a complex number in the Linear filter extraction framework. It seems as though this should eventually be a first class citizen of the IR, but they are not. For now, we'll convert back and forth between this and the structure that exists in the language (i.e. JFloatLiteral).
Complex numbers are immutable -- i.e. their value can't change after they are instantiated.
$Id: ComplexNumber.java,v 1.9 2006/01/25 17:02:30 thies Exp $


Field Summary
static double MAX_PRECISION
          The maximum difference between two complex numbers (either their real or imaginary parts) before the equals method will not distinguish them anymore.
static double MAX_PRECISION_BUFFER
           
static ComplexNumber ONE
          Canonical real number one.
static ComplexNumber ZERO
          Canonical number zero.
 
Constructor Summary
ComplexNumber(double re, double im)
          Create a complex number with real part re and imaginary part im.
 
Method Summary
 ComplexNumber conjugate()
          Returns the complex congugate of this complex number.
 ComplexNumber dividedby(ComplexNumber other)
          Divide this by the specified complex number and return the dividend.
static boolean doubleEquals(double d1, double d2)
          Returns true if these two doubles are equal within a certain precision.
 boolean equals(Object o)
          Return true if the passed complex number is the same as this (by value).
 double getImaginary()
          Get the imaginary part of this complex number.
 double getReal()
          Get the real part of this complex number.
 int hashCode()
          Hashcode so that data structures work correctly
 boolean isIntegral()
          returns true if both the real and imaginary parts of this are integers
 boolean isReal()
          returns true of abs(imaginary part) is less than MAX_PRECISION
 ComplexNumber negate()
          Compute the negative of this complex number.
 ComplexNumber plus(ComplexNumber other)
          Compute the sum of this and the passed complex number.
 ComplexNumber times(ComplexNumber other)
          Multiply this by the specified complex number, and return their product.
 String toString()
          PrettyPrint this complex number.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_PRECISION

public static final double MAX_PRECISION
The maximum difference between two complex numbers (either their real or imaginary parts) before the equals method will not distinguish them anymore. This is necessary because because of the imprecision of floating point arithmetic.

See Also:
Constant Field Values

MAX_PRECISION_BUFFER

public static final double MAX_PRECISION_BUFFER
See Also:
Constant Field Values

ZERO

public static final ComplexNumber ZERO
Canonical number zero.


ONE

public static final ComplexNumber ONE
Canonical real number one.

Constructor Detail

ComplexNumber

public ComplexNumber(double re,
                     double im)
Create a complex number with real part re and imaginary part im.

Method Detail

getReal

public double getReal()
Get the real part of this complex number.


getImaginary

public double getImaginary()
Get the imaginary part of this complex number.


isReal

public boolean isReal()
returns true of abs(imaginary part) is less than MAX_PRECISION


isIntegral

public boolean isIntegral()
returns true if both the real and imaginary parts of this are integers


negate

public ComplexNumber negate()
Compute the negative of this complex number.


plus

public ComplexNumber plus(ComplexNumber other)
Compute the sum of this and the passed complex number.


times

public ComplexNumber times(ComplexNumber other)
Multiply this by the specified complex number, and return their product.


dividedby

public ComplexNumber dividedby(ComplexNumber other)
Divide this by the specified complex number and return the dividend.


conjugate

public ComplexNumber conjugate()
Returns the complex congugate of this complex number. i.e. reverse the sign of the imaginary part).


equals

public boolean equals(Object o)
Return true if the passed complex number is the same as this (by value).

Overrides:
equals in class Object

doubleEquals

public static boolean doubleEquals(double d1,
                                   double d2)
Returns true if these two doubles are equal within a certain precision.


hashCode

public int hashCode()
Hashcode so that data structures work correctly

Overrides:
hashCode in class Object

toString

public String toString()
PrettyPrint this complex number.

Overrides:
toString in class Object