public class Complex extends Object implements Serializable
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.
Modifier and Type | Field and Description |
---|---|
static Complex |
I
The square root of -1.
|
protected double |
imaginary
Deprecated.
to be made final and private in 2.0
|
static Complex |
INF
A complex number representing "+INF + INFi".
|
static Complex |
NaN
A complex number representing "NaN + NaNi".
|
static Complex |
ONE
A complex number representing "1.0 + 0.0i"
|
protected double |
real
Deprecated.
to be made final and private in 2.0
|
static Complex |
ZERO
A complex number representing "0.0 + 0.0i"
|
Constructor and Description |
---|
Complex(double real,
double imaginary)
Create a complex number given the real and imaginary parts.
|
Modifier and Type | Method and Description |
---|---|
double |
abs()
Return the absolute value of this complex number.
|
Complex |
acos()
Compute the
inverse cosine of this complex number.
|
Complex |
add(Complex rhs)
Return the sum of this complex number and the given complex number.
|
Complex |
asin()
Compute the
inverse sine of this complex number.
|
Complex |
atan()
Compute the
inverse tangent of this complex number.
|
Complex |
conjugate()
Return the conjugate of this complex number.
|
Complex |
cos()
Compute the
cosine of this complex number.
|
Complex |
cosh()
Compute the
hyperbolic cosine of this complex number.
|
protected Complex |
createComplex(double real,
double imaginary)
Create a complex number given the real and imaginary parts.
|
Complex |
divide(Complex rhs)
Return the quotient of this complex number and the given complex number.
|
boolean |
equals(Object other)
Test for the equality of two Complex objects.
|
Complex |
exp()
Compute the
exponential function of this complex number.
|
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 |
log()
Compute the
natural logarithm of this complex number.
|
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 |
pow(Complex x)
Returns of value of this complex number raised to the power of
x . |
Complex |
sin()
Compute the
sine
of this complex number.
|
Complex |
sinh()
Compute the
hyperbolic sine of this complex number.
|
Complex |
sqrt()
Compute the
square root of this complex number.
|
Complex |
sqrt1z()
Compute the
square root of 1 -
this 2 for this complex
number. |
Complex |
subtract(Complex rhs)
Return the difference between this complex number and the given complex
number.
|
Complex |
tan()
Compute the
tangent of this complex number.
|
Complex |
tanh()
Compute the
hyperbolic tangent of this complex number.
|
public static final Complex I
public static final Complex NaN
public static final Complex INF
public static final Complex ONE
public static final Complex ZERO
@Deprecated protected double imaginary
@Deprecated protected double real
public Complex(double real, double imaginary)
real
- the real partimaginary
- the imaginary partpublic double abs()
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)
(a + bi) + (c + di) = (a+c) + (b+d)iIf 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 numberNullPointerException
- 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)
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 numberNullPointerException
- if rhs
is nullpublic boolean equals(Object other)
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
.public int hashCode()
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)
(a + bi)(c + di) = (ac - bd) + (ad + bc)i
Returns NaN
if either this or rhs
has one or more
NaN parts.
Returns INF
if neither this nor rhs
has one or more
NaN parts and if either this or rhs
has one or more infinite
parts (same result is returned regardless of the sign of the components).
Returns finite values in components of the result per the definitional
formula in all remaining cases.rhs
- the other complex numberNullPointerException
- if rhs
is nullpublic Complex negate()
Complex.NaN
if either real or imaginary part of this Complex
number equals Double.NaN
.public Complex subtract(Complex rhs)
(a + bi) - (c + di) = (a-c) + (b-d)iIf 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 numberNullPointerException
- if rhs
is nullpublic Complex acos()
acos(z) = -i (log(z + i (sqrt(1 - z2))))
Returns NaN
if either
real or imaginary part of the input argument is NaN
or
infinite.public Complex asin()
asin(z) = -i (log(sqrt(1 - z2) + iz))
Returns NaN
if either
real or imaginary part of the input argument is NaN
or
infinite.public Complex atan()
atan(z) = (i/2) log((i + z)/(i - z))
Returns NaN
if either
real or imaginary part of the input argument is NaN
or
infinite.public Complex cos()
cos(a + bi) = cos(a)cosh(b) - sin(a)sinh(b)i
where the (real) functions on the right-hand side are
Math.sin(double)
, Math.cos(double)
,
MathUtils.cosh(double)
and
MathUtils.sinh(double)
.
Returns NaN
if either
real or imaginary part of the input argument is NaN
.
Infinite values in real or imaginary parts of the input may result in
infinite or NaN values returned in parts of the result.
Examples:
cos(1 ± INFINITY i) = 1 #x2213; INFINITY i
cos(±INFINITY + i) = NaN + NaN i
cos(±INFINITY ± INFINITY i) = NaN + NaN i
public Complex cosh()
cosh(a + bi) = cosh(a)cos(b) + sinh(a)sin(b)i
where the (real) functions on the right-hand side are
Math.sin(double)
, Math.cos(double)
,
MathUtils.cosh(double)
and
MathUtils.sinh(double)
.
Returns NaN
if either
real or imaginary part of the input argument is NaN
.
Infinite values in real or imaginary parts of the input may result in
infinite or NaN values returned in parts of the result.
Examples:
cosh(1 ± INFINITY i) = NaN + NaN i
cosh(±INFINITY + i) = INFINITY ± INFINITY i
cosh(±INFINITY ± INFINITY i) = NaN + NaN i
public Complex exp()
exp(a + bi) = exp(a)cos(b) + exp(a)sin(b)i
where the (real) functions on the right-hand side are
Math.exp(double)
, Math.cos(double)
, and
Math.sin(double)
.
Returns NaN
if either
real or imaginary part of the input argument is NaN
.
Infinite values in real or imaginary parts of the input may result in
infinite or NaN values returned in parts of the result.
Examples:
exp(1 ± INFINITY i) = NaN + NaN i
exp(INFINITY + i) = INFINITY + INFINITY i
exp(-INFINITY + i) = 0 + 0i
exp(±INFINITY ± INFINITY i) = NaN + NaN i
this
public Complex log()
log(a + bi) = ln(|a + bi|) + arg(a + bi)i
where ln on the right hand side is Math.log(double)
,
|a + bi|
is the modulus,
abs()
, and
arg(a + bi) = Math.atan2(double, double)
(b, a)
Returns NaN
if either
real or imaginary part of the input argument is NaN
.
Infinite (or critical) values in real or imaginary parts of the input may
result in infinite or NaN values returned in parts of the result.
Examples:
log(1 ± INFINITY i) = INFINITY ± (π/2)i
log(INFINITY + i) = INFINITY + 0i
log(-INFINITY + i) = INFINITY + πi
log(INFINITY ± INFINITY i) = INFINITY ± (π/4)i
log(-INFINITY ± INFINITY i) = INFINITY ± (3π/4)i
log(0 + 0i) = -INFINITY + 0i
public Complex pow(Complex x)
x
. Implements the formula:
yx = exp(x·log(y))
where exp
and log
are exp()
and
log()
, respectively.
Returns NaN
if either
real or imaginary part of the input argument is NaN
or
infinite, or if y
equals
ZERO
.x
- the exponent.this
x
NullPointerException
- if x is nullpublic Complex sin()
sin(a + bi) = sin(a)cosh(b) - cos(a)sinh(b)i
where the (real) functions on the right-hand side are
Math.sin(double)
, Math.cos(double)
,
MathUtils.cosh(double)
and
MathUtils.sinh(double)
.
Returns NaN
if either
real or imaginary part of the input argument is NaN
.
Infinite values in real or imaginary parts of the input may result in
infinite or NaN values returned in parts of the result.
Examples:
sin(1 ± INFINITY i) = 1 ± INFINITY i
sin(±INFINITY + i) = NaN + NaN i
sin(±INFINITY ± INFINITY i) = NaN + NaN i
public Complex sinh()
sinh(a + bi) = sinh(a)cos(b)) + cosh(a)sin(b)i
where the (real) functions on the right-hand side are
Math.sin(double)
, Math.cos(double)
,
MathUtils.cosh(double)
and
MathUtils.sinh(double)
.
Returns NaN
if either
real or imaginary part of the input argument is NaN
.
Infinite values in real or imaginary parts of the input may result in
infinite or NaN values returned in parts of the result.
Examples:
sinh(1 ± INFINITY i) = NaN + NaN i
sinh(±INFINITY + i) = ± INFINITY + INFINITY i
sinh(±INFINITY ± INFINITY i) = NaN + NaN i
public Complex sqrt()
sqrt(a + bi)
:
t = sqrt((|a| + |a + bi|) / 2)
ifa ≥ 0
returnt + (b/2t)i
else return|b|/2t + sign(b)t i
|a| = Math.abs(int)
(a)
|a + bi| = abs()
(a + bi)
sign(b) = MathUtils.indicator(byte)
(b)
NaN
if either
real or imaginary part of the input argument is NaN
.
Infinite values in real or imaginary parts of the input may result in
infinite or NaN values returned in parts of the result.
Examples:
sqrt(1 ± INFINITY i) = INFINITY + NaN i
sqrt(INFINITY + i) = INFINITY + 0i
sqrt(-INFINITY + i) = 0 + INFINITY i
sqrt(INFINITY ± INFINITY i) = INFINITY + NaN i
sqrt(-INFINITY ± INFINITY i) = NaN ± INFINITY i
public Complex sqrt1z()
this
2 for this complex
number. Computes the result directly as
sqrt(Complex.ONE.subtract(z.multiply(z)))
.
Returns NaN
if either
real or imaginary part of the input argument is NaN
.
Infinite values in real or imaginary parts of the input may result in
infinite or NaN values returned in parts of the result.this
2public Complex tan()
tan(a + bi) = sin(2a)/(cos(2a)+cosh(2b)) + [sinh(2b)/(cos(2a)+cosh(2b))]i
where the (real) functions on the right-hand side are
Math.sin(double)
, Math.cos(double)
,
MathUtils.cosh(double)
and
MathUtils.sinh(double)
.
Returns NaN
if either
real or imaginary part of the input argument is NaN
.
Infinite (or critical) values in real or imaginary parts of the input may
result in infinite or NaN values returned in parts of the result.
Examples:
tan(1 ± INFINITY i) = 0 + NaN i
tan(±INFINITY + i) = NaN + NaN i
tan(±INFINITY ± INFINITY i) = NaN + NaN i
tan(±π/2 + 0 i) = ±INFINITY + NaN i
public Complex tanh()
tan(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]i
where the (real) functions on the right-hand side are
Math.sin(double)
, Math.cos(double)
,
MathUtils.cosh(double)
and
MathUtils.sinh(double)
.
Returns NaN
if either
real or imaginary part of the input argument is NaN
.
Infinite values in real or imaginary parts of the input may result in
infinite or NaN values returned in parts of the result.
Examples:
tanh(1 ± INFINITY i) = NaN + NaN i
tanh(±INFINITY + i) = NaN + 0 i
tanh(±INFINITY ± INFINITY i) = NaN + NaN i
tanh(0 + (π/2)i) = NaN + INFINITY i
protected Complex createComplex(double real, double imaginary)
real
- the real partimaginary
- the imaginary partCopyright © 2018. All rights reserved.