mae.tut.num
Class Complex

java.lang.Object
  extended bymae.tut.num.Number
      extended bymae.tut.num.Complex
All Implemented Interfaces:
java.io.Serializable

public class Complex
extends Number

Represents a complex number, implemented as x+iy.

Where x is the real part, y is the imaginary part.

Complex numbers can be compared for equality, but order is not defined.

See Also:
Serialized Form

Constructor Summary
Complex(float r, float i)
          Use factory method Factory.newComplex(float,float), rather than this constructor
 
Method Summary
 Number add(Number n)
          Adds this Number to another Number n and returns the result.
 float angle()
          Theta angle of polar coordinates, in the range of -90 through 270 degrees
 boolean equals(java.lang.Object x)
          Compares this Number to another Object for equality.
static Complex fromNumber(Number n)
          Converts Number n into Complex, if not already Complex
static Number fromPolar(float r, float a)
          Makes a (Complex) Number from polar coordinates
 Number inverse()
          Returns the multiplicative inverse of this Number.
 Number mult(Number n)
          Multiplies this Number by another Number n and returns the result.
 java.lang.String toPolar()
          String representation of this Number in polar coordinates
 java.lang.String toString()
          String representation of this Number in cartesian coordinates
 float value()
          Distance to origin (rho)
 
Methods inherited from class mae.tut.num.Number
hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Complex

public Complex(float r,
               float i)
Use factory method Factory.newComplex(float,float), rather than this constructor

Method Detail

add

public Number add(Number n)
Description copied from class: Number
Adds this Number to another Number n and returns the result.

If this Number and n are of the same type, returned result must be of that type.
If this and n are of different types, returned result must be as narrow as possible.
But in all cases add(n) and n.add(this) must return the same Number.

Specified by:
add in class Number

mult

public Number mult(Number n)
Description copied from class: Number
Multiplies this Number by another Number n and returns the result.

If this Number and n are of the same type, returned result must be of that type.
If this and n are of different types, returned result must be as narrow as possible.
But in all cases mult(n) and n.mult(this) must return the same Number.

Specified by:
mult in class Number

inverse

public Number inverse()
Description copied from class: Number
Returns the multiplicative inverse of this Number.

For any Number n, if inverse() is defined, n.inverse().inverse() must be equal to n.
Also n.inverse().mult(n).value() must be 1.0

Specified by:
inverse in class Number

value

public float value()
Distance to origin (rho)

Specified by:
value in class Number

angle

public float angle()
Theta angle of polar coordinates, in the range of -90 through 270 degrees


toPolar

public java.lang.String toPolar()
String representation of this Number in polar coordinates


toString

public java.lang.String toString()
String representation of this Number in cartesian coordinates


equals

public boolean equals(java.lang.Object x)
Compares this Number to another Object for equality.

The result is true if and only if the argument (not null) is a Complex with the same field values
OR this Number happens to be real with the same value as x.


fromPolar

public static Number fromPolar(float r,
                               float a)
Makes a (Complex) Number from polar coordinates


fromNumber

public static Complex fromNumber(Number n)
Converts Number n into Complex, if not already Complex