public final class Complex extends Object implements Serializable
Implementations of arithmetic operations handle NaN and
infinite values according to the rules for Double, i.e.
equals(java.lang.Object) is an equivalence relation for all instances that have
a NaN in either real or imaginary part, e.g. the following are
considered equal:
1 + NaNiNaN + iNaN + NaNi
Note that this contradicts the IEEE-754 standard for floating
point numbers (according to which the test x == x must fail if
x is NaN). The method
equals for primitive double in class Precision conforms with
IEEE-754 while this class conforms with the standard behavior for Java
object types.
| Modifier and Type | Field and Description |
|---|---|
static Complex |
I
The square root of -1, a.k.a.
|
static Complex |
INF
A complex number representing "+INF + INF i"
|
static Complex |
ONE
A complex number representing one.
|
static Complex |
ZERO
A complex number representing zero.
|
| 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 |
acosh()
Compute the
inverse hyperbolic cosine of this complex number.
|
Complex |
add(Complex addend)
Returns a
Complex whose value is
(this + addend). |
Complex |
add(double addend)
Returns a
Complex whose value is (this + addend),
with addend interpreted as a real number. |
double |
arg()
Compute the argument of this complex number.
|
Complex |
asin()
Compute the
inverse sine of this complex number.
|
Complex |
asinh()
Compute the
inverse hyperbolic sine of this complex number.
|
Complex |
atan()
Compute the
inverse tangent of this complex number.
|
Complex |
atanh()
Compute the
inverse hyperbolic tangent of this complex number.
|
Complex |
conj()
Returns the conjugate of this complex number.
|
Complex |
conjugate()
Returns 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.
|
Complex |
divide(Complex divisor)
Returns a
Complex whose value is
(this / divisor). |
Complex |
divide(double divisor)
Returns a
Complex whose value is (this / divisor),
with divisor interpreted as a real number. |
static boolean |
equals(Complex x,
Complex y)
Returns
true iff the values are equal as defined by
equals(x, y, 1). |
static boolean |
equals(Complex x,
Complex y,
double eps)
Returns
true if, both for the real part and for the imaginary
part, there is no double value strictly between the arguments or the
difference between them is within the range of allowed error
(inclusive). |
static boolean |
equals(Complex x,
Complex y,
int maxUlps)
Test for the floating-point equality between Complex objects.
|
boolean |
equals(Object other)
Test for equality with another object.
|
static boolean |
equalsWithRelativeTolerance(Complex x,
Complex y,
double eps)
Returns
true if, both for the real part and for the imaginary
part, there is no double value strictly between the arguments or the
relative difference between them is smaller or equal to the given
tolerance. |
Complex |
exp()
Compute the
exponential function of this complex number.
|
double |
getArgument()
Compute the argument of this complex number.
|
double |
getImaginary()
Access the imaginary part.
|
double |
getReal()
Access the real part.
|
int |
hashCode()
Get a hash code for the complex number.
|
double |
imag()
Access the imaginary part (C++ grammar)
|
boolean |
isInfinite()
Returns true if either real or imaginary component of the Complex
is Infinite
|
boolean |
isNaN()
Returns true if either real or imaginary component of the Complex
is NaN
|
Complex |
log()
Compute the
natural logarithm of this complex number.
|
Complex |
log10()
Compute the base 10 or
common logarithm of this complex number.
|
Complex |
multiply(Complex factor)
Returns a
Complex whose value is this * factor. |
Complex |
multiply(double factor)
Returns a
Complex whose value is this * factor, with factor
interpreted as a real number. |
Complex |
multiply(int factor)
Returns a
Complex whose value is this * factor, with factor
interpreted as a integer number. |
Complex |
negate()
Returns a
Complex whose value is (-this). |
List<Complex> |
nthRoot(int n)
Computes the n-th roots of this complex number.
|
static Complex |
ofCartesian(double real,
double imaginary)
Create a complex number given the real and imaginary parts.
|
static Complex |
ofCis(double x)
For a real constructor argument x, returns a new Complex object c
where
c = cos(x) + i sin (x) |
static Complex |
ofPolar(double r,
double theta)
Creates a Complex from its polar representation.
|
static Complex |
ofReal(double real)
Create a complex number given the real part.
|
static Complex |
parse(String s)
Parses a string that would be produced by
toString()
and instantiates the corresponding object. |
Complex |
pow(Complex x)
Returns of value of this complex number raised to the power of
x. |
Complex |
pow(double x)
Returns of value of this complex number raised to the power of
x. |
Complex |
proj()
Returns projection of this complex number onto the Riemann sphere,
i.e.
|
double |
real()
Access the real part (C++ grammar)
|
Complex |
reciprocal()
Returns the multiplicative inverse of this instance.
|
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 |
square()
Compute the square of this complex number.
|
Complex |
subtract(Complex subtrahend)
Returns a
Complex whose value is
(this - subtrahend). |
Complex |
subtract(double subtrahend)
Returns a
Complex whose value is
(this - subtrahend). |
Complex |
tan()
Compute the
tangent of this complex number.
|
Complex |
tanh()
Compute the
hyperbolic tangent of this complex number.
|
String |
toString() |
public static final Complex I
public static final Complex INF
public static final Complex ONE
public static final Complex ZERO
public static Complex ofCartesian(double real, double imaginary)
real - Real part.imaginary - Imaginary part.Complex objectpublic static Complex ofReal(double real)
real - Real part.Complex objectpublic static Complex ofPolar(double r, double theta)
r is infinite and theta is finite, infinite or NaN
values may be returned in parts of the result, following the rules for
double arithmetic.
Examples:
polar2Complex(INFINITY, \(\pi\)) = INFINITY + INFINITY i
polar2Complex(INFINITY, 0) = INFINITY + NaN i
polar2Complex(INFINITY, \(-\frac{\pi}{4}\)) = INFINITY - INFINITY i
polar2Complex(INFINITY, \(5\frac{\pi}{4}\)) = -INFINITY - INFINITY i
r - the modulus of the complex number to createtheta - the argument of the complex number to createComplexpublic static Complex ofCis(double x)
c = cos(x) + i sin (x)x - double to build the cis numberComplexpublic static Complex parse(String s)
toString()
and instantiates the corresponding object.s - String representation.IllegalArgumentException - if the string does not
conform to the specification.public boolean isNaN()
booleanpublic boolean isInfinite()
booleanpublic Complex proj()
Complex projected onto the Riemann sphere.public double abs()
public Complex add(Complex addend)
Complex whose value is
(this + addend).
Uses the definitional formula
(a + bi) + (c + di) = (a+c) + (b+d)i
addend - Value to be added to this Complex.this + addend.public Complex add(double addend)
Complex whose value is (this + addend),
with addend interpreted as a real number.addend - Value to be added to this Complex.this + addend.add(Complex)public Complex conjugate()
a + bi is a - bi.public Complex conj()
public Complex divide(Complex divisor)
Complex whose value is
(this / divisor).
Implements the definitional formula
a + bi ac + bd + (bc - ad)i
----------- = -------------------------
c + di c2 + d2
Recalculates to recover infinities as specified in C.99
standard G.5.1. Method is fully in accordance with
C++11 standards for complex numbers.divisor - Value by which this Complex is to be divided.this / divisor.public Complex divide(double divisor)
Complex whose value is (this / divisor),
with divisor interpreted as a real number.divisor - Value by which this Complex is to be divided.this / divisor.divide(Complex)public Complex reciprocal()
1 / this.divide(Complex)public boolean equals(Object other)
Double.NaN, the two
Complex objects are considered to be equal.
The behavior is the same as for JDK's Double:
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 NaN.
public static boolean equals(Complex x, Complex y, int maxUlps)
true if both arguments are equal or within the
range of allowed error (inclusive).x - First value (cannot be null).y - Second value (cannot be null).maxUlps - (maxUlps - 1) is the number of floating point
values between the real (resp. imaginary) parts of x and
y.true if there are fewer than maxUlps floating
point values between the real (resp. imaginary) parts of x
and y.Precision.equals(double,double,int)public static boolean equals(Complex x, Complex y)
true iff the values are equal as defined by
equals(x, y, 1).x - First value (cannot be null).y - Second value (cannot be null).true if the values are equal.public static boolean equals(Complex x, Complex y, double eps)
true if, both for the real part and for the imaginary
part, there is no double value strictly between the arguments or the
difference between them is within the range of allowed error
(inclusive). Returns false if either of the arguments is NaN.x - First value (cannot be null).y - Second value (cannot be null).eps - Amount of allowed absolute error.true if the values are two adjacent floating point
numbers or they are within range of each other.Precision.equals(double,double,double)public static boolean equalsWithRelativeTolerance(Complex x, Complex y, double eps)
true if, both for the real part and for the imaginary
part, there is no double value strictly between the arguments or the
relative difference between them is smaller or equal to the given
tolerance. Returns false if either of the arguments is NaN.x - First value (cannot be null).y - Second value (cannot be null).eps - Amount of allowed relative error.true if the values are two adjacent floating point
numbers or they are within range of each other.Precision.equalsWithRelativeTolerance(double,double,double)public int hashCode()
Double.NaN value in real or imaginary part produces
the same hash code 7.public double getImaginary()
public double imag()
public double getReal()
public double real()
public Complex multiply(Complex factor)
Complex whose value is this * factor.
Implements the definitional formula:
(a + bi)(c + di) = (ac - bd) + (ad + bc)i
Recalculates to recover infinities as specified in C.99
standard G.5.1. Method is fully in accordance with
C++11 standards for complex numbers.factor - value to be multiplied by this Complex.this * factor.public Complex multiply(int factor)
Complex whose value is this * factor, with factor
interpreted as a integer number.factor - value to be multiplied by this Complex.this * factor.multiply(Complex)public Complex multiply(double factor)
Complex whose value is this * factor, with factor
interpreted as a real number.factor - value to be multiplied by this Complex.this * factor.multiply(Complex)public Complex negate()
Complex whose value is (-this).-this.public Complex subtract(Complex subtrahend)
Complex whose value is
(this - subtrahend).
Uses the definitional formula
(a + bi) - (c + di) = (a-c) + (b-d)i
subtrahend - value to be subtracted from this Complex.this - subtrahend.public Complex subtract(double subtrahend)
Complex whose value is
(this - subtrahend).subtrahend - value to be subtracted from this Complex.this - subtrahend.subtract(Complex)public Complex acos()
acos(z) = -i (log(z + i (sqrt(1 - z<sup>2</sup>))))
public Complex asin()
asin(z) = -i (log(sqrt(1 - z<sup>2</sup>) + iz))
public Complex atan()
atan(z) = (i/2) log((i + z)/(i - z))
public Complex asinh()
asinh(z) = log(z+sqrt(z^2+1))
public Complex atanh()
atanh(z) = log((1+z)/(1-z))/2
public Complex acosh()
acosh(z) = log(z+sqrt(z^2-1))
public Complex square()
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),
Math.cosh(double) and Math.sinh(double).
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),
Math.cosh(double) and Math.sinh(double).
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).ethis.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).ln this, the natural logarithm
of this.public Complex log10()
this.public Complex pow(Complex x)
x.
Implements the formula:
yx = exp(x·log(y))
where exp and log are exp() and
log(), respectively.x - exponent to which this Complex is to be raised. thisx.public Complex pow(double x)
x.x - exponent to which this Complex is to be raised.thisx.pow(Complex)public 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),
Math.cosh(double) and Math.sinh(double).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),
Math.cosh(double) and Math.sinh(double).this.public Complex sqrt()
sqrt(a + bi):
t = sqrt((|a| + |a + bi|) / 2)ifa ≥ 0returnt + (b/2t)ielse return|b|/2t + sign(b)t i
|a| = Math.abs(int)(a)|a + bi| = abs()(a + bi)sign(b) = copySign(1d, b)
this.public 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), Math.cosh(double) and
Math.sinh(double).this.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), Math.cosh(double) and
Math.sinh(double).this.public double getArgument()
If either real or imaginary part (or both) is NaN, NaN is returned.
Infinite parts are handled as Math.atan2 handles them,
essentially treating finite parts as zero in the presence of an
infinite coordinate and returning a multiple of pi/4 depending on
the signs of the infinite parts.
See the javadoc for Math.atan2 for full details.
this.public double arg()
this.public List<Complex> nthRoot(int n)
zk = abs1/n (cos(phi + 2πk/n) + i (sin(phi + 2πk/n))
for k=0, 1, ..., n-1, where abs and phi
are respectively the modulus and
argument of this complex number.
If one or both parts of this complex number is NaN, a list with just
one element, NaN + NaN i is returned.
if neither part is NaN, but at least one part is infinite, the result
is a one-element list containing INF.
n - Degree of root.n-th roots of this.Copyright © 2017–2018 The Apache Software Foundation. All rights reserved.