public class Complex extends Number implements Field<Complex>, NumberUtils.Comparable<Complex>
Field.InverseNonExistent| Modifier and Type | Field and Description |
|---|---|
static Complex |
I
a number representing 0.0 + 1.0i, the square root of -1
|
static Complex |
NaN
a number representing the complex Not-a-Number (
NaN) |
static Complex |
NEGATIVE_INFINITY
a number representing -∞ + -∞i
|
static Complex |
ONE
a number representing 1.0 + 0.0i
|
static Complex |
POSITIVE_INFINITY
a number representing +∞ + ∞i
|
static Complex |
ZERO
a number representing 0.0 + 0.0i
|
| Constructor and Description |
|---|
Complex(double a)
Construct a complex number from a real number.
|
Complex(double a,
double b)
Construct a complex number from the real and imaginary parts.
|
| Modifier and Type | Method and Description |
|---|---|
Complex |
add(Complex that)
+ : G × G → G
|
double |
arg()
Get the θ of the complex number in polar representation.
|
int |
compare(Number that,
double epsilon)
Compare
this and that numbers up to a precision. |
Complex |
conjugate()
Get the conjugate of the complex number, namely, (a - bi).
|
Complex |
divide(Complex that)
Compute the quotient of this complex number divided by another complex number.
|
double |
doubleValue() |
boolean |
equals(Object obj) |
float |
floatValue() |
static Complex |
fromPolar(double r,
double theta)
Factory method to construct a complex number from the polar form: (r, θ).
|
int |
hashCode() |
double |
imaginary()
Get the imaginary part of this complex number.
|
int |
intValue()
Deprecated.
Invalid operation.
|
Complex |
inverse()
For each a in F, there exists an element b in F such that
a × b = b × a = 1.
|
static boolean |
isInfinite(Complex z)
Check if a complex number is an infinity;
i.e., either the real or the imaginary part is infinite, c.f.,
Double.isInfinite(),
and the number is not a NaN. |
static boolean |
isNaN(Complex z)
Check if a complex number is an
NaN;
i.e., either the real or the imaginary part is an NaN. |
static boolean |
isReal(Complex z)
Check if this complex number is a real number;
i.e., the imaginary part is 0.
|
long |
longValue()
Deprecated.
Invalid operation.
|
Complex |
minus(Complex that)
- : G × G → G
The operation "-" is not in the definition of of an additive group but can be deduced.
|
double |
modulus()
Get the modulus.
|
Complex |
multiply(Complex that)
Compute the product of this complex number and that complex number.
|
Complex |
ONE()
Get one - the number representing 1.0 + 0.0i.
|
Complex |
opposite()
For each a in G, there exists an element b in G such that
a + b = b + a = 0.
|
double |
real()
Get the real part of this complex number.
|
Double |
toDouble()
Cast the complex number to a
Double if it is a real number. |
String |
toString() |
Complex |
ZERO()
Get zero - the number representing 0.0 + 0.0i.
|
byteValue, shortValuepublic static final Complex I
public static final Complex ZERO
public static final Complex ONE
public static final Complex POSITIVE_INFINITY
public static final Complex NEGATIVE_INFINITY
public static final Complex NaN
NaN)public Complex(double a,
double b)
a - the real partb - the imaginary partpublic Complex(double a)
a - a real numberpublic static Complex fromPolar(double r, double theta)
r - a radiustheta - an anglepublic double real()
public double imaginary()
public static boolean isReal(Complex z)
z - a complex numbertrue if the imaginary part is 0public static boolean isNaN(Complex z)
NaN;
i.e., either the real or the imaginary part is an NaN.z - a complex numbertrue if either the real or the imaginary part is a NaNpublic static boolean isInfinite(Complex z)
Double.isInfinite(),
and the number is not a NaN.z - a complex numbertrue if either the real or the imaginary part is infinitepublic double modulus()
this.modulus() * this.modulus() = this.multiply(this.conjugate())
Math.hypot(double, double)public double arg()
public Double toDouble()
Double if it is a real number.IllegalArgumentException - if this complex number is not a real numberpublic Complex conjugate()
@Deprecated public int intValue()
@Deprecated public long longValue()
public float floatValue()
floatValue in class Numberpublic double doubleValue()
doubleValue in class Numberpublic Complex add(Complex that)
AbelianGroupadd in interface AbelianGroup<Complex>that - the object to be addedpublic Complex minus(Complex that)
AbelianGroupthis.add(that.opposite()).minus in interface AbelianGroup<Complex>that - the object to be subtracted (subtrahend)public Complex opposite()
AbelianGroupthis.add(this.opposite()) == this.ZEROopposite in interface AbelianGroup<Complex>public Complex inverse() throws Field.InverseNonExistent
Fieldthis.multiply(this.inverse()) == this.ONEinverse in interface Field<Complex>Field.InverseNonExistent - if the inverse does not existpublic Complex divide(Complex that)
We develop a simple method for scaling to avoid overflow and harmful underflow in complex division. The method guarantees that no overflow will occur unless at least one component of the quotient must overflow, otherwise the normwise error in the computed result is at most a few units in the last place. Moreover, the scaling requires only four floating point multiplications and a small amount of integer arithmetic to compute the scale factor. Thus, on many modern CPUs, our method is both safer and faster than Smith's widely used algorithm.
divide in interface Field<Complex>that - the denominatorArithmeticException - if division by zero happenspublic Complex multiply(Complex that)
(a + bi)(c + di) = (ac - bd) + (ad + bc)iThis implementation is more efficient by doing 1 less multiplication:
(a + bi)(c + di) = (ac - bd) + ((a + b)(c + d) - ac - bd)i
public Complex ZERO()
ZERO in interface AbelianGroup<Complex>public Complex ONE()
public int compare(Number that, double epsilon)
NumberUtils.Comparablethis and that numbers up to a precision.compare in interface NumberUtils.Comparable<Complex>that - a Number.
As a number can be represented in multiple ways, e.g., 0 = 0 + 0i, the
implementation may need to check Object type.epsilon - a precision parameter: when a number |x| ≤ ε, it is considered
0this is bigger; -1 if
that is biggerCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.