org.rubato.math.arith
Class Complex

java.lang.Object
  extended by java.lang.Number
      extended by org.rubato.math.arith.Complex
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Complex>

public final class Complex
extends java.lang.Number
implements java.lang.Comparable<Complex>, java.lang.Cloneable

Complex number arithmetic.

Author:
Gérard Milmeister
See Also:
Serialized Form

Constructor Summary
Complex()
          Creates the complex number 0+i0.
Complex(Complex c)
          Creates a new complex number from c.
Complex(double real)
          Creates the complex number real+i0.
Complex(double real, double imag)
          Creates the complex number real+i*imag.
Complex(int real)
          Creates the complex number real+i0.
Complex(java.lang.String s)
          Creates a new complex number from its string representation.
 
Method Summary
 double abs()
          Returns the absolute value of this number.
 Complex acos()
          Returns the arccosine of this number.
 void add(Complex c)
          Adds the complex number c to this number.
 void add(double x)
          Adds the real number x to this number.
 double arg()
          Returns the argument of this number.
 Complex asin()
          Returns the arcsine of this number.
 Complex atan(Complex c)
          Returns the arctangent of this number and c.
 java.lang.Object clone()
           
 int compareTo(Complex c)
          Compares this number with object.
 void conjugate()
          Conjugates this number.
 Complex conjugated()
          Returns the conjugate of this number.
 Complex cos()
          Returns the cosine of this number.
 Complex difference(Complex c)
          Returns the difference of this number and c.
 Complex difference(double x)
          Returns the difference of this number and x.
 void divide(Complex c)
          Divides this number by c.
 void divide(double x)
          Divides this number by x.
 double doubleValue()
          Returns the real part of the complex number as a double.
 Complex exp()
          Returns the exponential of this number.
 Complex expt(Complex c)
          Returns this number raised to the power c.
 float floatValue()
          Returns the real part of the complex number as a float.
static Complex fromPolar(double r, double phi)
          Creates a complex number with the polar representation r*e^(i*phi).
 double getImag()
          Returns the imaginary part of this number.
static Complex getOne()
          Returns the complex number 1+i0.
 double getReal()
          Returns the real part of this number.
static Complex getZero()
          Returns the complex number 0+i0.
 int hashCode()
          Returns hashcode for this number.
 int intValue()
          Returns the real part of the complex number rounded to an integer.
 Complex inverse()
          Returns the inverse of this number.
 void invert()
          Inverts this number.
 boolean isOne()
          Returns true iff this number is 1+i0.
 boolean isReal()
          Returns true iff the imaginary part is zero.
 boolean isZero()
          Returns true iff this number is 0+i0.
 Complex log()
          Returns the natural logarithm of this number.
 long longValue()
          Returns the real part of the complex number rounded to a long.
 void multiply(Complex c)
          Multiplies this number with c.
 void negate()
          Negates this number.
 Complex negated()
          Returns the negative of this number.
static Complex parseComplex(java.lang.String s)
          Returns the complex number with the string representation s
 Complex product(Complex c)
          Returns the product of this number and c.
 Complex product(double x)
          Returns the product of this number and the real number x.
 Complex quotient(Complex c)
          Returns the quotient of this number by c.
 Complex quotient(double x)
          Returns the quotient of this number by x.
 Complex sin()
          Returns the sine of this number.
 Complex sqrt()
          Returns the square root of this number.
 void subtract(Complex c)
          Subtracts the complex number c from this number.
 Complex sum(Complex c)
          Returns the sum of this number and c.
 Complex sum(double x)
          Returns the sum of this number and x.
 Complex tan()
          Returns the tangent of this number.
 java.lang.String toString()
          Returns the string representation of this number.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Complex

public Complex()
Creates the complex number 0+i0.


Complex

public Complex(double real,
               double imag)
Creates the complex number real+i*imag.


Complex

public Complex(double real)
Creates the complex number real+i0.


Complex

public Complex(int real)
Creates the complex number real+i0.


Complex

public Complex(Complex c)
Creates a new complex number from c.


Complex

public Complex(java.lang.String s)
Creates a new complex number from its string representation.

Parameters:
s - must be of the form "x+i*y" where x and y are string representations of doubles, or of one of the forms "i*x" or "i"
Method Detail

fromPolar

public static Complex fromPolar(double r,
                                double phi)
Creates a complex number with the polar representation r*e^(i*phi).

Parameters:
r - the absolute value of the complex number
phi - the argument of the complex number

intValue

public int intValue()
Returns the real part of the complex number rounded to an integer.

Specified by:
intValue in class java.lang.Number

longValue

public long longValue()
Returns the real part of the complex number rounded to a long.

Specified by:
longValue in class java.lang.Number

floatValue

public float floatValue()
Returns the real part of the complex number as a float.

Specified by:
floatValue in class java.lang.Number

doubleValue

public double doubleValue()
Returns the real part of the complex number as a double.

Specified by:
doubleValue in class java.lang.Number

getOne

public static Complex getOne()
Returns the complex number 1+i0.


getZero

public static Complex getZero()
Returns the complex number 0+i0.


sum

public Complex sum(Complex c)
Returns the sum of this number and c.


sum

public Complex sum(double x)
Returns the sum of this number and x.


add

public void add(Complex c)
Adds the complex number c to this number.


add

public void add(double x)
Adds the real number x to this number.


difference

public Complex difference(Complex c)
Returns the difference of this number and c.


difference

public Complex difference(double x)
Returns the difference of this number and x.


subtract

public void subtract(Complex c)
Subtracts the complex number c from this number.


product

public Complex product(Complex c)
Returns the product of this number and c.


product

public Complex product(double x)
Returns the product of this number and the real number x.


multiply

public void multiply(Complex c)
Multiplies this number with c.


quotient

public Complex quotient(Complex c)
Returns the quotient of this number by c.


quotient

public Complex quotient(double x)
Returns the quotient of this number by x.


divide

public void divide(Complex c)
Divides this number by c.


divide

public void divide(double x)
Divides this number by x.


inverse

public Complex inverse()
Returns the inverse of this number.


invert

public void invert()
Inverts this number.


negated

public Complex negated()
Returns the negative of this number.


negate

public void negate()
Negates this number.


conjugated

public Complex conjugated()
Returns the conjugate of this number.


conjugate

public void conjugate()
Conjugates this number.


isZero

public boolean isZero()
Returns true iff this number is 0+i0.


isOne

public boolean isOne()
Returns true iff this number is 1+i0.


getReal

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


getImag

public double getImag()
Returns the imaginary part of this number.


isReal

public boolean isReal()
Returns true iff the imaginary part is zero.


abs

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


arg

public double arg()
Returns the argument of this number.


sqrt

public Complex sqrt()
Returns the square root of this number.


log

public Complex log()
Returns the natural logarithm of this number.


exp

public Complex exp()
Returns the exponential of this number.


expt

public Complex expt(Complex c)
Returns this number raised to the power c.


sin

public Complex sin()
Returns the sine of this number.


cos

public Complex cos()
Returns the cosine of this number.


tan

public Complex tan()
Returns the tangent of this number.


asin

public Complex asin()
Returns the arcsine of this number.


acos

public Complex acos()
Returns the arccosine of this number.


atan

public Complex atan(Complex c)
Returns the arctangent of this number and c.


hashCode

public int hashCode()
Returns hashcode for this number.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns the string representation of this number.

Overrides:
toString in class java.lang.Object

parseComplex

public static Complex parseComplex(java.lang.String s)
Returns the complex number with the string representation s


clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

compareTo

public int compareTo(Complex c)
Compares this number with object. Since complex numbers are not linearly ordered, the comparison is lexicographic.

Specified by:
compareTo in interface java.lang.Comparable<Complex>