public final class Complex extends Object
Constructor and Description 

Complex()
Create a complex number equal to
0 + 0i . 
Complex(Complex other)
Create a complex number that has the same real and imaginary parts as
another complex number.

Complex(double re)
Create a complex number with a zero imaginary part and a given real part.

Complex(double re,
double im)
Create a complex number with the given real and imaginary components.

Modifier and Type  Method and Description 

Complex 
add(Complex c)
Add this complex number and another complex number to obtain a new complex
number.

boolean 
equals(Object obj)
Compares this complex number with the specifed object.

static Complex 
fromPolar(double magnitude,
double theta)
Returns a reference to a new
Complex number given its
polar form. 
int 
hashCode()
Return a hash code for this complex number.

double 
im()
Get the imaginary part of the complex number.

double 
mag()
Compute the magnitude of this complex number.

Complex 
multiply(Complex c)
Multiply this complex number with another complex number to obtain a new
complex number.

double 
re()
Get the real part of the complex number.

String 
toString()
Returns a string representation of this complex number.

public Complex()
0 + 0i
.public Complex(double re)
re
 The real part of the complex number.public Complex(Complex other)
other
 The complex number to copy.public Complex(double re, double im)
re
 The real part of the complex number.im
 The imaginary part of the complex number.public double re()
public double im()
public Complex add(Complex c)
c
 The complex number to add to this complex number.Complex
number equal to the sum of this complex
number and c
.public Complex multiply(Complex c)
This is not an industrial strength implementation of complex number
multiplication. In particular, issues related to the differences between
0.0
and 0.0
and infinite real or imaginary parts
are not taken into account.
c
 The complex number to multiply by.Complex
number equal to this complex number
multiplied by c
.public double mag()
public int hashCode()
public boolean equals(Object obj)
true
if and only if the argument is a Complex
number with the same real and imaginary parts as this complex number.
The comparisons of the real and imaginary parts are performed in a manner
consistent with Double.compare(double, double)
).
public String toString()
The returned string is the real part of the complex number, followed by a
space, followed by a +
or 
sign, followed by a
space, followed by the absolute value of the imaginary part of the complex
number, followed by an i
. The sign is +
if the
imaginary part of the complex number is positive, and 
if the
imaginary part of the complex number is negative.
For example the complex number with real and imaginary parts equal to zero
has the string representation 0.0 + 0.0i
. The complex number
with real part equal to zero and imaginary part equal to 1
has the string representation 0.0  1.0i
.
public static Complex fromPolar(double magnitude, double theta)
Complex
number given its
polar form.
The polar form of a complex number can be drawn in a twodimensional
Cartesian coordinate system as a vector from the origin to the
coordinates (re, im)
where re
is the
real part of the complex number and im
is the imaginary
part of the complex number.
The polar form is given as a nonnegative magnitude and an angle θ from the positive real axis. The real and imaginary components can be computed from the polar form as:
re = magnitude * cos(θ)
im = magnitude * sin(θ)
If magnitude
is equal to zero, then the complex number
0.0 + 0.0i
is returned.
magnitude
 the magnitude of the complex numbertheta
 the angle in radians from the real axisComplex
number equal to the given polar formIllegalArugmentException
 if magnitude < 0.0