vec_math
Class Complex

java.lang.Object
  extended by java.lang.Number
      extended by vec_math.Complex
All Implemented Interfaces:
Serializable

public class Complex
extends Number

A number representing a complex number. All methods that access the number as a primitive data type return the length of the complex number. A complex number always consists of two Doubles, the real part and the imaginary part.

See Also:
Serialized Form

Field Summary
private  double imaginary
          The imaginary part of the complex.
private  double real
          The real part of the complex.
 
Constructor Summary
Complex(double r, double i)
          Constructs a new Complex from two primitive doubles, the first is the real part, the second the imaginary part.
Complex(String comp)
          Constructs a new Complex from a String.
 
Method Summary
 Complex add(Complex b)
          return a new object whose value is (this + b)
 Complex conjugate()
           
 double doubleValue()
          Converts the complex to a double.
 boolean equals(Object other)
          Checks for equality.
 float floatValue()
          Converts the complex to a float.
 double getImaginary()
          Returns the imaginary part.
 double getReal()
          Returns the real part of the complex.
 int intValue()
          Converts the complex to an integer.
 double length()
          Returns the length of this complex.
 double lengthSq()
          Returns the square length of this complex.
 long longValue()
          Converts the complex to a long.
static void main(String[] arg)
          Testing.
 Complex multiply(Complex b)
          return a new object whose value is (this * b)
 Complex multiply(double alpha)
          return a new complex stretched by the factor.
 Complex subtract(Complex b)
          return a new object whose value is (this - b)
 double theta()
          Returns the theta of this complex.
 String toString()
          Retunrs the complex as a string.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

real

private double real
The real part of the complex.


imaginary

private double imaginary
The imaginary part of the complex.

Constructor Detail

Complex

public Complex(String comp)
Constructs a new Complex from a String. The format of the string must be two doubles, separated by the letter 'i', without any whitespaces.


Complex

public Complex(double r,
               double i)
Constructs a new Complex from two primitive doubles, the first is the real part, the second the imaginary part.

Method Detail

intValue

public int intValue()
Converts the complex to an integer. Returns the length of the complex.

Specified by:
intValue in class Number

longValue

public long longValue()
Converts the complex to a long. The rounded length is returned.

Specified by:
longValue in class Number

floatValue

public float floatValue()
Converts the complex to a float. The length is returned.

Specified by:
floatValue in class Number

doubleValue

public double doubleValue()
Converts the complex to a double. The length is returned.

Specified by:
doubleValue in class Number

theta

public double theta()
Returns the theta of this complex.


length

public double length()
Returns the length of this complex.


lengthSq

public double lengthSq()
Returns the square length of this complex.


getReal

public double getReal()
Returns the real part of the complex.


getImaginary

public double getImaginary()
Returns the imaginary part.


add

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


subtract

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


multiply

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


multiply

public Complex multiply(double alpha)
return a new complex stretched by the factor.


conjugate

public Complex conjugate()

equals

public boolean equals(Object other)
Checks for equality. Two Complex are equal if both, their real and their imaginary parts are equal.

Overrides:
equals in class Object

toString

public String toString()
Retunrs the complex as a string. The string representation can be used in the constructor.

Overrides:
toString in class Object

main

public static void main(String[] arg)
Testing.