org.apache.commons.math.complex
Class Complex

java.lang.Object
  extended byorg.apache.commons.math.complex.Complex
All Implemented Interfaces:
Serializable

public class Complex
extends Object
implements Serializable

Representation of a Complex number - a number which has both a real and imaginary part.

Version:
$Revision: 1.9 $ $Date: 2004/06/23 16:26:16 $
Author:
Apache Software Foundation
See Also:
Serialized Form

Field Summary
static Complex I
          The square root of -1.
protected  double imaginary
          The imaginary part.
static Complex NaN
          A complex number representing "(Double.NaN) + (Double.NaN)i"
static Complex ONE
          A complex number representing "1.0 + 0.0i"
protected  double real
          The real part.
(package private) static long serialVersionUID
          Serializable version identifier
 
Constructor Summary
Complex(double real, double imaginary)
          Create a complex number given the real and imaginary parts.
 
Method Summary
 double abs()
          Return the absolute value of this complex number.
 Complex add(Complex rhs)
          Return the sum of this complex number and the given complex number.
 Complex conjugate()
          Return the conjugate of this complex number.
 Complex divide(Complex rhs)
          Return the quotient of this complex number and the given complex number.
 boolean equals(Object other)
          Test for the equality of two Complex objects.
 double getImaginary()
          Access the imaginary part.
 double getReal()
          Access the real part.
 boolean isNaN()
          Returns true if this complex number is the special Not-a-Number (NaN) value.
 Complex multiply(Complex rhs)
          Return the product of this complex number and the given complex number.
 Complex negate()
          Return the additive inverse of this complex number.
 Complex subtract(Complex rhs)
          Return the difference between this complex number and the given complex number.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
Serializable version identifier

See Also:
Constant Field Values

I

public static final Complex I
The square root of -1. A number representing "0.0 + 1.0i".


NaN

public static final Complex NaN
A complex number representing "(Double.NaN) + (Double.NaN)i"


ONE

public static final Complex ONE
A complex number representing "1.0 + 0.0i"


imaginary

protected double imaginary
The imaginary part.


real

protected double real
The real part.

Constructor Detail

Complex

public Complex(double real,
               double imaginary)
Create a complex number given the real and imaginary parts.

Parameters:
real - the real part.
imaginary - the imaginary part.
Method Detail

abs

public double abs()
Return the absolute value of this complex number.

Returns:
the absolute value.

add

public Complex add(Complex rhs)
Return the sum of this complex number and the given complex number.

Parameters:
rhs - the other complex number.
Returns:
the complex number sum.

conjugate

public Complex conjugate()
Return the conjugate of this complex number. The conjugate of "A + Bi" is "A - Bi". Complex.NaN is returned if either the real or imaginary part of this Complex number equals Double.NaN.

Returns:
the conjugate of this Complex object

divide

public Complex divide(Complex rhs)
Return the quotient of this complex number and the given complex number.

Parameters:
rhs - the other complex number.
Returns:
the complex number quotient.

equals

public boolean equals(Object other)
Test for the equality of two Complex objects. If both the real and imaginary parts of two Complex numbers are exactly the same, the two Complex objects are considered to be equal.

Parameters:
other - Object to test for equality to this
Returns:
true if two Complex objects are equal, false if object is null, not an instance of Complex, or not equal to this Complex instance.

getImaginary

public double getImaginary()
Access the imaginary part.

Returns:
the imaginary part.

getReal

public double getReal()
Access the real part.

Returns:
the real part.

isNaN

public boolean isNaN()
Returns true if this complex number is the special Not-a-Number (NaN) value.

Returns:
true if the value represented by this object is NaN; false otherwise.

multiply

public Complex multiply(Complex rhs)
Return the product of this complex number and the given complex number.

Parameters:
rhs - the other complex number.
Returns:
the complex number product.

negate

public Complex negate()
Return the additive inverse of this complex number.

Returns:
the negation of this complex number.

subtract

public Complex subtract(Complex rhs)
Return the difference between this complex number and the given complex number.

Parameters:
rhs - the other complex number.
Returns:
the complex number difference.


Copyright © 2003-2004 The Apache Software Foundation. All Rights Reserved.