repthy
Class Complex

Object
  extended byComplex

public class Complex
extends Object

An implementation of complex numbers as pairs of doubles.

Author:
Mark McConnell

Field Summary
static Complex I
          The constant i.
static Complex NEG_I
          The constant -i.
static Complex NEG_ONE
          The constant -1.
static Complex ONE
          The constant 1.
static Complex ZERO
          The constant 0.
 
Constructor Summary
Complex(double re)
           
Complex(double re, double im)
           
Complex(int re)
           
 
Method Summary
 Complex add(Complex w)
           
 Complex add(double real)
           
 Complex add(int real)
           
 double arg()
          Returns the arg, in the range -pi to pi.
 Complex conjugate()
           
static Complex getRootOf1(int j, int n)
          Returns the jth power of the primitive nth root of unity e^(2 pi i / n).
 double Im()
           
static void main(String[] args)
          For testing.
 Complex mult(Complex w)
           
 Complex mult(double real)
           
 Complex mult(int real)
           
 Complex multByConj(Complex w)
          Returns this times the conjugate of w.
 double norm()
           
 String printAsGaussianInteger()
          Rounds the real and imaginary parts to the nearest integer (long), then prints as if by toString().
 double Re()
           
 long roundToLong()
          Returns the real part rounded to the nearest integer.
 Complex subtract(Complex w)
           
 Complex subtract(double real)
           
 Complex subtract(int real)
           
 String toString()
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Complex ZERO
The constant 0.


ONE

public static final Complex ONE
The constant 1.


I

public static final Complex I
The constant i.


NEG_ONE

public static final Complex NEG_ONE
The constant -1.


NEG_I

public static final Complex NEG_I
The constant -i.

Constructor Detail

Complex

public Complex(double re,
               double im)

Complex

public Complex(double re)

Complex

public Complex(int re)
Method Detail

Re

public final double Re()

Im

public final double Im()

add

public Complex add(Complex w)

add

public Complex add(double real)

add

public Complex add(int real)

subtract

public Complex subtract(Complex w)

subtract

public Complex subtract(double real)

subtract

public Complex subtract(int real)

mult

public Complex mult(Complex w)

mult

public Complex mult(double real)

mult

public Complex mult(int real)

multByConj

public Complex multByConj(Complex w)
Returns this times the conjugate of w.


conjugate

public Complex conjugate()

getRootOf1

public static Complex getRootOf1(int j,
                                 int n)
Returns the jth power of the primitive nth root of unity e^(2 pi i / n).

Throws:
IllegalArgumentException - If n is less than or equal to 0.

norm

public double norm()

arg

public double arg()
Returns the arg, in the range -pi to pi.

Throws:
ArithmeticException - if this = 0.

roundToLong

public long roundToLong()
Returns the real part rounded to the nearest integer.


toString

public String toString()

printAsGaussianInteger

public String printAsGaussianInteger()
Rounds the real and imaginary parts to the nearest integer (long), then prints as if by toString().


main

public static void main(String[] args)
For testing. Give it four double arguments.