org.openuat.features
Class Complex

java.lang.Object
  extended by org.openuat.features.Complex

public class Complex
extends java.lang.Object

Data type for complex numbers. The data type is "immutable" so once you create and initialize a complex object, you cannot change its value. The "final" keyword when declaring re and im enforces this rule, making it a compile-time error to change the .re or .im fields after they've been initialized.

Author:
Adapted by Rene Mayrhofer, very heavily based on code by Robert Sedgewick and Kevin Wayne

Constructor Summary
Complex(double real, double imag)
          Create a new object with the given real and imaginary parts.
 
Method Summary
 double abs()
          return |this|
 Complex conjugate()
          return a new object whose value is the conjugate of this.
 double getIm()
          Return the imaginary part.
 double getRe()
          Return the real part.
static void main(java.lang.String[] args)
           
 Complex minus(Complex b)
          return a new object whose value is (this - b).
 Complex plus(Complex b)
          return a new object whose value is (this + b).
 Complex times(Complex b)
          return a new object whose value is (this * b).
 Complex times(double alpha)
          return a new object whose value is (this * alpha).
 java.lang.String toString()
          return a string representation of the invoking object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Complex

public Complex(double real,
               double imag)
Create a new object with the given real and imaginary parts.

Method Detail

toString

public java.lang.String toString()
return a string representation of the invoking object.

Overrides:
toString in class java.lang.Object

abs

public double abs()
return |this|


plus

public Complex plus(Complex b)
return a new object whose value is (this + b).


minus

public Complex minus(Complex b)
return a new object whose value is (this - b).


times

public Complex times(Complex b)
return a new object whose value is (this * b).


times

public Complex times(double alpha)
return a new object whose value is (this * alpha).


conjugate

public Complex conjugate()
return a new object whose value is the conjugate of this.


getRe

public double getRe()
Return the real part.


getIm

public double getIm()
Return the imaginary part.


main

public static void main(java.lang.String[] args)


2005-2009, Rene Mayrhofer.