org.metasyntactic.math
Class Complex

java.lang.Object
  |
  +--org.metasyntactic.math.Complex
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Complex
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

The lack of built-in complex arithmetic in Java is a nuisance for numerical work. Even in languages like FORTRAN that have complex data types, it is disconcertingly common to encounter complex operations that produce overflows or underflows when both the complex operands and the complex result are perfectly representable. This occurs, I think, because software companies assign inexperienced programmers to what they believe to be the perfectly trivial task of implementing complex arithmetic.

The routines contianed in this class are the best known ones for effeciently and correctly determining values for complex functions, while at the same time avoiding over and underflow problems

All instances of Complex Number are immutable (just like java primitives).

See Also:
Serialized Form

Field Summary
static Complex I
           
static Complex ZERO
           
 
Constructor Summary
Complex(Complex complex)
          Copy constructor
Complex(double real, double imaginary)
           
 
Method Summary
 Complex add(Complex b)
           
 Complex conjugate()
           
 Complex divide(Complex b)
           
 boolean equals(Complex c)
           
 boolean equals(java.lang.Object o)
           
 double getImaginary()
           
 double getReal()
           
 int hashCode()
           
static void main(java.lang.String[] args)
           
 double modulus()
           
 Complex multiply(Complex b)
           
 Complex squareRoot()
           
 Complex subtract(Complex b)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

I

public static final Complex I

ZERO

public static final Complex ZERO
Constructor Detail

Complex

public Complex(double real,
               double imaginary)
Parameters:
real - The real component of this Complex number
imaginary - The imaginary component of this Compex number

Complex

public Complex(Complex complex)
Copy constructor

Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

equals

public boolean equals(Complex c)

add

public Complex add(Complex b)

subtract

public Complex subtract(Complex b)

multiply

public Complex multiply(Complex b)

modulus

public double modulus()

divide

public Complex divide(Complex b)

squareRoot

public Complex squareRoot()
Returns:
The square root of this Complex number

conjugate

public Complex conjugate()

getReal

public double getReal()
Returns:
The real component of this Complex number

getImaginary

public double getImaginary()
Returns:
The imaginary component of this Compex number

main

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