|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math.complex.Complex
public class Complex
Representation of a Complex number - a number which has both a real and imaginary part.
Implementations of arithmetic operations handle NaN
and
infinite values according to the rules for Double
arithmetic, applying definitional formulas and returning NaN
or
infinite values in real or imaginary parts as these arise in computation.
See individual method javadocs for details.
equals(java.lang.Object)
identifies all values with NaN
in either real
or imaginary part - e.g.,
1 + NaNi == NaN + i == NaN + NaNi.
Field Summary | |
---|---|
static Complex |
I
The square root of -1. |
protected double |
imaginary
The imaginary part |
static Complex |
NaN
A complex number representing "NaN + NaNi" |
static Complex |
ONE
A complex number representing "1.0 + 0.0i" |
protected double |
real
The real part |
private static long |
serialVersionUID
Serializable version identifier |
static Complex |
ZERO
A complex number representing "0.0 + 0.0i" |
Constructor Summary | |
---|---|
Complex(double real,
double imaginary)
Create a complex number given the real and imaginary parts. |
Method Summary | |
---|---|
double |
abs()
Return the absolute value of this complex number. |
Complex |
add(Complex rhs)
Return the sum of this complex number and the given complex number. |
Complex |
conjugate()
Return the conjugate of this complex number. |
Complex |
divide(Complex rhs)
Return the quotient of this complex number and the given complex number. |
boolean |
equals(java.lang.Object other)
Test for the equality of two Complex objects. |
double |
getImaginary()
Access the imaginary part. |
double |
getReal()
Access the real part. |
int |
hashCode()
Get a hashCode for the complex number. |
boolean |
isInfinite()
Returns true if either the real or imaginary part of this complex number takes an infinite value (either Double.POSITIVE_INFINITY or
Double.NEGATIVE_INFINITY ) and neither part
is NaN . |
boolean |
isNaN()
Returns true if either or both parts of this complex number is NaN; false otherwise |
Complex |
multiply(Complex rhs)
Return the product of this complex number and the given complex number. |
Complex |
negate()
Return the additive inverse of this complex number. |
Complex |
subtract(Complex rhs)
Return the difference between this complex number and the given complex number. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
public static final Complex I
public static final Complex NaN
public static final Complex ONE
public static final Complex ZERO
protected double imaginary
protected double real
Constructor Detail |
---|
public Complex(double real, double imaginary)
real
- the real partimaginary
- the imaginary partMethod Detail |
---|
public double abs()
Returns NaN
if either real or imaginary part is
NaN
and Double.POSITIVE_INFINITY
if
neither part is NaN
, but at least one part takes an infinite
value.
public Complex add(Complex rhs)
Uses the definitional formula
(a + bi) + (c + di) = (a+c) + (b+d)i
If either this or rhs
has a NaN value in either part,
NaN
is returned; otherwise Inifinite and NaN values are
returned in the parts of the result according to the rules for
Double
arithmetic.
rhs
- the other complex number
java.lang.NullPointerException
- if rhs
is nullpublic Complex conjugate()
NaN
is returned if either the real or imaginary
part of this Complex number equals Double.NaN
.
If the imaginary part is infinite, and the real part is not NaN,
the returned value has infinite imaginary part of the opposite
sign - e.g. the conjugate of 1 + POSITIVE_INFINITY i
is 1 - NEGATIVE_INFINITY i
public Complex divide(Complex rhs)
Implements the definitional formula
a + bi ac + bd + (bc - ad)i
----------- = -------------------------
c + di c2 + d2
but uses
prescaling of operands to limit the effects of overflows and
underflows in the computation.
Infinite and NaN values are handled / returned according to the following rules, applied in the order presented:
rhs
has a NaN value in either part,
NaN
is returned.rhs
equals ZERO
, NaN
is returned.
rhs
are both infinite,
NaN
is returned.rhs
is infinite (one or both parts infinite),
ZERO
is returned.rhs
is finite, NaN values are
returned in the parts of the result if the Double
rules applied to the definitional formula force NaN results.
rhs
- the other complex number
java.lang.NullPointerException
- if rhs
is nullpublic boolean equals(java.lang.Object other)
If both the real and imaginary parts of two Complex numbers
are exactly the same, and neither is Double.NaN
, the two
Complex objects are considered to be equal.
All NaN
values are considered to be equal - i.e, if either
(or both) real and imaginary parts of the complex number are equal
to Double.NaN
, the complex number is equal to
Complex.NaN
.
equals
in class java.lang.Object
other
- Object to test for equality to this
public int hashCode()
All NaN values have the same hash code.
hashCode
in class java.lang.Object
public double getImaginary()
public double getReal()
public boolean isNaN()
public boolean isInfinite()
Double.POSITIVE_INFINITY
or
Double.NEGATIVE_INFINITY
) and neither part
is NaN
.
NaN
public Complex multiply(Complex rhs)
Implements the definitional formula:
(a + bi)(c + di) = (ac - bd) + (ad + bc)i
Returns NaN
if either this or rhs
has one or more
NaN parts.
Returns NaN or infinite values in components of the result per the
definitional formula and and the rules for Double
arithmetic. Examples:
(1 + i) (INF + i) = INF + INFi
(1 + INFi) (1 - INFi) = INF + NaNi
(-INF + -INFi)(1 + NaNi) = NaN + NaNi
rhs
- the other complex number
java.lang.NullPointerException
- if rhs
is nullpublic Complex negate()
Returns Complex.NaN
if either real or imaginary
part of this Complex number equals Double.NaN
.
public Complex subtract(Complex rhs)
Uses the definitional formula
(a + bi) - (c + di) = (a-c) + (b-d)i
If either this or rhs
has a NaN value in either part,
NaN
is returned; otherwise inifinite and NaN values are
returned in the parts of the result according to the rules for
Double
arithmetic.
rhs
- the other complex number
java.lang.NullPointerException
- if rhs
is null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |