Treeviz 0.37 2010-10-17

ch.randelshofer.util
Class Complex

java.lang.Object
  extended by ch.randelshofer.util.Complex
All Implemented Interfaces:
java.lang.Cloneable

public class Complex
extends java.lang.Object
implements java.lang.Cloneable

Immutable complex number of the form x+bi.

Version:
1.0 2008-07-07 Created.
Author:
Werner Randelshofer

Constructor Summary
Complex(double x, double y)
          Creates a complex number with the real part x and the imaginary part y.
 
Method Summary
 Complex add(Complex that)
          Returns a complex number whose value is (this + that).
static Complex add(Complex a, Complex b)
          Returns a complex number whose value is (a + b).
 double arg()
          Returns the argument of this complex number (the angle in radians with the x-axis in polar coordinates).
 Complex clone()
          Returns a clone of this complex number.
 Complex div(Complex that)
          Returns a complex number whose value is (this / that).
static Complex div(Complex a, Complex b)
          Returns a complex number whose value is (a / b).
 boolean equals(java.lang.Object o)
          Returns true of this complex number is equal to the specified complex number.
 int hashCode()
          Returns a hash code for this complex number.
 double img()
          Returns the imaginary part of the complex number.
 boolean isNaN()
          Returns true if this complex numer is not a number (NaN).
static void main(java.lang.String[] args)
           
 double mod()
          Returns the modulo of this complex number.
 Complex mul(Complex that)
          Returns a complex number whose value is (this * that).
static Complex mul(Complex a, Complex b)
          Returns a complex number whose value is (a * b).
 double real()
          Returns the real part of the complex number.
 Complex sqrt()
          Returns the principal branch of the square root of this complex number.
 Complex sub(Complex that)
          Returns a complex number whose value is (this - that).
static Complex sub(Complex a, Complex b)
          Returns a complex number whose value is (a - b).
 java.lang.String toString()
          Returns a descriptive string representation of this complex number.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Complex

public Complex(double x,
               double y)
Creates a complex number with the real part x and the imaginary part y.

Parameters:
x - real part of the complex number
y - imaginary part of the complex number
Method Detail

real

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

Returns:
real part.

img

public double img()
Returns the imaginary part of the complex number.

Returns:
real part.

add

public Complex add(Complex that)
Returns a complex number whose value is (this + that).

Parameters:
that - A complex number.
Returns:
this + that.

add

public static Complex add(Complex a,
                          Complex b)
Returns a complex number whose value is (a + b).

Parameters:
a - A complex number.
b - A complex number.
Returns:
a + b.

sub

public Complex sub(Complex that)
Returns a complex number whose value is (this - that).

Parameters:
that - A complex number.
Returns:
this - that.

sub

public static Complex sub(Complex a,
                          Complex b)
Returns a complex number whose value is (a - b).

Parameters:
a - A complex number.
b - A complex number.
Returns:
a - b.

mul

public Complex mul(Complex that)
Returns a complex number whose value is (this * that).

Parameters:
that - A complex number.
Returns:
this * that.

mul

public static Complex mul(Complex a,
                          Complex b)
Returns a complex number whose value is (a * b).

Parameters:
a - A complex number.
b - A complex number.
Returns:
a * b.

div

public Complex div(Complex that)
Returns a complex number whose value is (this / that).

Parameters:
that - A complex number.
Returns:
this / that.

div

public static Complex div(Complex a,
                          Complex b)
Returns a complex number whose value is (a / b).

Parameters:
a - A complex number.
b - A complex number.
Returns:
a / b.

arg

public double arg()
Returns the argument of this complex number (the angle in radians with the x-axis in polar coordinates).

Returns:
atan2(y, x).

mod

public double mod()
Returns the modulo of this complex number.

Returns:
sqrt(x*x + y*y).

sqrt

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

Returns:
square root.

equals

public boolean equals(java.lang.Object o)
Returns true of this complex number is equal to the specified complex number.

Overrides:
equals in class java.lang.Object
Returns:
true if equal.

hashCode

public int hashCode()
Returns a hash code for this complex number.

Overrides:
hashCode in class java.lang.Object
Returns:
hash code.

clone

public Complex clone()
Returns a clone of this complex number.

Overrides:
clone in class java.lang.Object
Returns:
a clone.

toString

public java.lang.String toString()
Returns a descriptive string representation of this complex number.

Overrides:
toString in class java.lang.Object
Returns:
a descriptive string.

isNaN

public boolean isNaN()
Returns true if this complex numer is not a number (NaN).

Returns:
true if NaN.

main

public static void main(java.lang.String[] args)

Copyright 2007-2008 (c) Werner Randelshofer.
All rights reserved.