Class Complex
- All Implemented Interfaces:
Serializable
,Comparable<Complex>
,CalculusFieldElement<Complex>
,FieldElement<Complex>
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 + NaNi
NaN + i
NaN + 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 Precision
conforms with IEEE-754 while this class conforms with the standard behavior
for Java object types.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Complex
The square root of -1.static final Complex
A complex number representing "+INF + INFi"static final Complex
The square root of -1.static final Complex
A complex number representing "-1.0 + 0.0i".static final Complex
A complex number representing "NaN + NaNi".static final Complex
A complex number representing "1.0 + 0.0i".static final Complex
A complex number representing "π + 0.0i".static final Complex
A complex number representing "0.0 + 0.0i". -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabs()
Return the absolute value of this complex number.acos()
Compute the inverse cosine of this complex number.acosh()
Inverse hyperbolic cosine operation.add
(double addend) Returns aComplex
whose value is(this + addend)
, withaddend
interpreted as a real number.Returns aComplex
whose value is(this + addend)
.asin()
Compute the inverse sine of this complex number.asinh()
Inverse hyperbolic sine operation.atan()
Compute the inverse tangent of this complex number.Two arguments arc tangent operation.atanh()
Inverse hyperbolic tangent operation.cbrt()
Cubic root.ceil()
Get the smallest whole number larger than instance.int
Returns the conjugate of this complex number.copySign
(double r) Returns the instance with the sign of the argument.Returns the instance with the sign of the argument.cos()
Compute the cosine of this complex number.cosh()
Compute the hyperbolic cosine of this complex number.protected Complex
createComplex
(double realPart, double imaginaryPart) Create a complex number given the real and imaginary parts.divide
(double divisor) Returns aComplex
whose value is(this / divisor)
, withdivisor
interpreted as a real number.Returns aComplex
whose value is(this / divisor)
.boolean
Test for equality with another object.static boolean
Returnstrue
iff the values are equal as defined byequals(x, y, 1)
.static boolean
Returnstrue
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
Test for the floating-point equality between Complex objects.static boolean
equalsWithRelativeTolerance
(Complex x, Complex y, double eps) Returnstrue
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.exp()
Compute the exponential function of this complex number.expm1()
Exponential minus 1.floor()
Get the largest whole number smaller than instance.double
Compute the argument of this complex number.getField()
Get theField
to which the instance belongs.double
Access the imaginary part.double
Access the imaginary part.getPi()
Get the Archimedes constant π.double
getReal()
Access the real part.double
Access the real part.int
hashCode()
Get a hashCode for the complex number.Returns the hypotenuse of a triangle with sidesthis
andy
- sqrt(this2 +y2) avoiding intermediate overflow or underflow.boolean
Checks whether either the real or imaginary part of this complex number takes an infinite value (eitherDouble.POSITIVE_INFINITY
orDouble.NEGATIVE_INFINITY
) and neither part isNaN
.boolean
Check whether the instance is an integer (i.e.boolean
isNaN()
Checks whether either or both parts of this complex number isNaN
.boolean
isReal()
Check whether the instance is real (i.e.boolean
isZero()
Check if an element is semantically equal to zero.linearCombination
(double[] a, Complex[] b) Compute a linear combination.linearCombination
(double a1, Complex b1, double a2, Complex b2) Compute a linear combination.linearCombination
(double a1, Complex b1, double a2, Complex b2, double a3, Complex b3) Compute a linear combination.linearCombination
(double a1, Complex b1, double a2, Complex b2, double a3, Complex b3, double a4, Complex b4) Compute a linear combination.linearCombination
(Complex[] a, Complex[] b) Compute a linear combination.linearCombination
(Complex a1, Complex b1, Complex a2, Complex b2) Compute a linear combination.Compute a linear combination.linearCombination
(Complex a1, Complex b1, Complex a2, Complex b2, Complex a3, Complex b3, Complex a4, Complex b4) Compute a linear combination.log()
Compute the natural logarithm of this complex number.log10()
Base 10 logarithm.log1p()
Shifted natural logarithm.multiply
(double factor) Returns aComplex
whose value isthis * factor
, withfactor
interpreted as a real number.multiply
(int factor) Returns aComplex
whose value isthis * factor
, withfactor
interpreted as a integer number.Returns aComplex
whose value isthis * factor
.Compute this *- -i.Compute this * i.negate()
Returns aComplex
whose value is(-this)
.newInstance
(double realPart) Create an instance corresponding to a constant real value.double
norm()
norm.nthRoot
(int n) Computes the n-th roots of this complex number.pow
(double x) Returns of value of this complex number raised to the power ofx
.pow
(int n) Integer power operation.Returns of value of this complex number raised to the power ofx
.protected final Object
Resolve the transient fields in a deserialized Complex Object.Returns the multiplicative inverse ofthis
element.remainder
(double a) IEEE remainder operator.IEEE remainder operator.rint()
Get the whole number that is the nearest to the instance, or the even one if x is exactly half way between two integers.rootN
(int n) Nth root.scalb
(int n) Multiply the instance by a power of 2.sign()
Compute the sign of the instance.sin()
Compute the sine of this complex number.sinCos()
Combined Sine and Cosine operation.sinh()
Compute the hyperbolic sine of this complex number.sinhCosh()
Combined hyperbolic sine and cosine operation.sqrt()
Compute the square root of this complex number.sqrt1z()
Compute the square root of1 - this2
for this complex number.square()
Compute this × this.subtract
(double subtrahend) Returns aComplex
whose value is(this - subtrahend)
.Returns aComplex
whose value is(this - subtrahend)
.tan()
Compute the tangent of this complex number.tanh()
Compute the hyperbolic tangent of this complex number.Convert radians to degrees, with error of less than 0.5 ULPConvert degrees to radians, with error of less than 0.5 ULPtoString()
ulp()
Compute least significant bit (Unit in Last Position) for a number.static Complex
valueOf
(double realPart) Create a complex number given only the real part.static Complex
valueOf
(double realPart, double imaginaryPart) Create a complex number given the real and imaginary parts.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.hipparchus.CalculusFieldElement
getExponent, isFinite, round
-
Field Details
-
I
The square root of -1. A number representing "0.0 + 1.0i". -
MINUS_I
The square root of -1. A number representing "0.0 - 1.0i".- Since:
- 1.7
-
NaN
A complex number representing "NaN + NaNi". -
INF
A complex number representing "+INF + INFi" -
ONE
A complex number representing "1.0 + 0.0i". -
MINUS_ONE
A complex number representing "-1.0 + 0.0i".- Since:
- 1.7
-
ZERO
A complex number representing "0.0 + 0.0i". -
PI
A complex number representing "π + 0.0i".
-
-
Constructor Details
-
Complex
public Complex(double real) Create a complex number given only the real part.- Parameters:
real
- Real part.
-
Complex
public Complex(double real, double imaginary) Create a complex number given the real and imaginary parts.- Parameters:
real
- Real part.imaginary
- Imaginary part.
-
-
Method Details
-
abs
Return the absolute value of this complex number. ReturnsNaN
if either real or imaginary part isNaN
andDouble.POSITIVE_INFINITY
if neither part isNaN
, but at least one part is infinite.- Specified by:
abs
in interfaceCalculusFieldElement<Complex>
- Returns:
- the norm.
- Since:
- 2.0
-
norm
public double norm()norm.- Specified by:
norm
in interfaceCalculusFieldElement<Complex>
- Returns:
- norm(this)
-
add
Returns aComplex
whose value is(this + addend)
. Uses the definitional formula(a + bi) + (c + di) = (a+c) + (b+d)i
this
oraddend
has aNaN
value in either part,NaN
is returned; otherwiseInfinite
andNaN
values are returned in the parts of the result according to the rules forDouble
arithmetic.- Specified by:
add
in interfaceFieldElement<Complex>
- Parameters:
addend
- Value to be added to thisComplex
.- Returns:
this + addend
.- Throws:
NullArgumentException
- ifaddend
isnull
.
-
add
Returns aComplex
whose value is(this + addend)
, withaddend
interpreted as a real number.- Specified by:
add
in interfaceCalculusFieldElement<Complex>
- Parameters:
addend
- Value to be added to thisComplex
.- Returns:
this + addend
.- See Also:
-
conjugate
Returns the conjugate of this complex number. The conjugate ofa + bi
isa - bi
.NaN
is returned if either the real or imaginary part of this Complex number equalsDouble.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 of1 + POSITIVE_INFINITY i
is1 - NEGATIVE_INFINITY i
.- Returns:
- the conjugate of this Complex object.
-
divide
Returns aComplex
whose value is(this / divisor)
. Implements the definitional formulaa + bi ac + bd + (bc - ad)i ----------- = ------------------------- c + di c2 + d2
Infinite
andNaN
values are handled according to the following rules, applied in the order presented:- If either
this
ordivisor
has aNaN
value in either part,NaN
is returned. - If
divisor
equalsZERO
,NaN
is returned. - If
this
anddivisor
are both infinite,NaN
is returned. - If
this
is finite (i.e., has noInfinite
orNaN
parts) anddivisor
is infinite (one or both parts infinite),ZERO
is returned. - If
this
is infinite anddivisor
is finite,NaN
values are returned in the parts of the result if theDouble
rules applied to the definitional formula forceNaN
results.
- Specified by:
divide
in interfaceCalculusFieldElement<Complex>
- Specified by:
divide
in interfaceFieldElement<Complex>
- Parameters:
divisor
- Value by which thisComplex
is to be divided.- Returns:
this / divisor
.- Throws:
NullArgumentException
- ifdivisor
isnull
.
- If either
-
divide
Returns aComplex
whose value is(this / divisor)
, withdivisor
interpreted as a real number.- Specified by:
divide
in interfaceCalculusFieldElement<Complex>
- Parameters:
divisor
- Value by which thisComplex
is to be divided.- Returns:
this / divisor
.- See Also:
-
reciprocal
Returns the multiplicative inverse ofthis
element.- Specified by:
reciprocal
in interfaceFieldElement<Complex>
- Returns:
- the inverse of
this
.
-
equals
Test for equality with another object. If both the real and imaginary parts of two complex numbers are exactly the same, and neither isDouble.NaN
, the two Complex objects are considered to be equal. The behavior is the same as for JDK'sDouble
:- All
NaN
values are considered to be equal, i.e, if either (or both) real and imaginary parts of the complex number are equal toDouble.NaN
, the complex number is equal toNaN
. - Instances constructed with different representations of zero (i.e. either "0" or "-0") are not considered to be equal.
- All
-
equals
Test for the floating-point equality between Complex objects. It returnstrue
if both arguments are equal or within the range of allowed error (inclusive).- Parameters:
x
- First value (cannot benull
).y
- Second value (cannot benull
).maxUlps
-(maxUlps - 1)
is the number of floating point values between the real (resp. imaginary) parts ofx
andy
.- Returns:
true
if there are fewer thanmaxUlps
floating point values between the real (resp. imaginary) parts ofx
andy
.- See Also:
-
equals
Returnstrue
iff the values are equal as defined byequals(x, y, 1)
.- Parameters:
x
- First value (cannot benull
).y
- Second value (cannot benull
).- Returns:
true
if the values are equal.
-
equals
Returnstrue
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). Returnsfalse
if either of the arguments is NaN.- Parameters:
x
- First value (cannot benull
).y
- Second value (cannot benull
).eps
- Amount of allowed absolute error.- Returns:
true
if the values are two adjacent floating point numbers or they are within range of each other.- See Also:
-
equalsWithRelativeTolerance
Returnstrue
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. Returnsfalse
if either of the arguments is NaN.- Parameters:
x
- First value (cannot benull
).y
- Second value (cannot benull
).eps
- Amount of allowed relative error.- Returns:
true
if the values are two adjacent floating point numbers or they are within range of each other.- See Also:
-
hashCode
public int hashCode()Get a hashCode for the complex number. AnyDouble.NaN
value in real or imaginary part produces the same hash code7
. -
isZero
public boolean isZero()Check if an element is semantically equal to zero.The default implementation simply calls
equals(getField().getZero())
. However, this may need to be overridden in some cases as due to compatibility withhashCode()
some classes implementsequals(Object)
in such a way that -0.0 and +0.0 are different, which may be a problem. It prevents for example identifying a diagonal element is zero and should be avoided when doing partial pivoting in LU decomposition.This implementation considers +0.0 and -0.0 to be equal for both real and imaginary components.
- Specified by:
isZero
in interfaceFieldElement<Complex>
- Returns:
- true if the element is semantically equal to zero
- Since:
- 1.8
-
getImaginary
public double getImaginary()Access the imaginary part.- Returns:
- the imaginary part.
-
getImaginaryPart
public double getImaginaryPart()Access the imaginary part.- Returns:
- the imaginary part.
- Since:
- 2.0
-
getReal
public double getReal()Access the real part.- Specified by:
getReal
in interfaceFieldElement<Complex>
- Returns:
- the real part.
-
getRealPart
public double getRealPart()Access the real part.- Returns:
- the real part.
- Since:
- 2.0
-
isNaN
public boolean isNaN()Checks whether either or both parts of this complex number isNaN
.- Specified by:
isNaN
in interfaceCalculusFieldElement<Complex>
- Returns:
- true if either or both parts of this complex number is
NaN
; false otherwise.
-
isReal
public boolean isReal()Check whether the instance is real (i.e. imaginary part is zero).- Returns:
- true if imaginary part is zero
- Since:
- 1.7
-
isMathematicalInteger
public boolean isMathematicalInteger()Check whether the instance is an integer (i.e. imaginary part is zero and real part has no fractional part).- Returns:
- true if imaginary part is zero and real part has no fractional part
- Since:
- 1.7
-
isInfinite
public boolean isInfinite()Checks whether either the real or imaginary part of this complex number takes an infinite value (eitherDouble.POSITIVE_INFINITY
orDouble.NEGATIVE_INFINITY
) and neither part isNaN
.- Specified by:
isInfinite
in interfaceCalculusFieldElement<Complex>
- Returns:
- true if one or both parts of this complex number are infinite
and neither part is
NaN
.
-
multiply
Returns aComplex
whose value isthis * factor
. Implements preliminary checks forNaN
and infinity followed by the definitional formula:(a + bi)(c + di) = (ac - bd) + (ad + bc)i
NaN
if eitherthis
orfactor
has one or moreNaN
parts.Returns
INF
if neitherthis
norfactor
has one or moreNaN
parts and if eitherthis
orfactor
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.
- Specified by:
multiply
in interfaceFieldElement<Complex>
- Parameters:
factor
- value to be multiplied by thisComplex
.- Returns:
this * factor
.- Throws:
NullArgumentException
- iffactor
isnull
.
-
multiply
Returns aComplex
whose value isthis * factor
, withfactor
interpreted as a integer number.- Specified by:
multiply
in interfaceCalculusFieldElement<Complex>
- Specified by:
multiply
in interfaceFieldElement<Complex>
- Parameters:
factor
- value to be multiplied by thisComplex
.- Returns:
this * factor
.- See Also:
-
multiply
Returns aComplex
whose value isthis * factor
, withfactor
interpreted as a real number.- Specified by:
multiply
in interfaceCalculusFieldElement<Complex>
- Parameters:
factor
- value to be multiplied by thisComplex
.- Returns:
this * factor
.- See Also:
-
multiplyPlusI
Compute this * i.- Returns:
- this * i
- Since:
- 2.0
-
multiplyMinusI
Compute this *- -i.- Returns:
- this * i
- Since:
- 2.0
-
square
Compute this × this.- Specified by:
square
in interfaceCalculusFieldElement<Complex>
- Returns:
- a new element representing this × this
-
negate
Returns aComplex
whose value is(-this)
. ReturnsNaN
if either real or imaginary part of this Complex number isDouble.NaN
.- Specified by:
negate
in interfaceFieldElement<Complex>
- Returns:
-this
.
-
subtract
Returns aComplex
whose value is(this - subtrahend)
. Uses the definitional formula(a + bi) - (c + di) = (a-c) + (b-d)i
this
orsubtrahend
has aNaN]
value in either part,NaN
is returned; otherwise infinite andNaN
values are returned in the parts of the result according to the rules forDouble
arithmetic.- Specified by:
subtract
in interfaceCalculusFieldElement<Complex>
- Specified by:
subtract
in interfaceFieldElement<Complex>
- Parameters:
subtrahend
- value to be subtracted from thisComplex
.- Returns:
this - subtrahend
.- Throws:
NullArgumentException
- ifsubtrahend
isnull
.
-
subtract
Returns aComplex
whose value is(this - subtrahend)
.- Specified by:
subtract
in interfaceCalculusFieldElement<Complex>
- Parameters:
subtrahend
- value to be subtracted from thisComplex
.- Returns:
this - subtrahend
.- See Also:
-
acos
Compute the inverse cosine of this complex number. Implements the formula:acos(z) = -i (log(z + i (sqrt(1 - z<sup>2</sup>))))
NaN
if either real or imaginary part of the input argument isNaN
or infinite.- Specified by:
acos
in interfaceCalculusFieldElement<Complex>
- Returns:
- the inverse cosine of this complex number.
-
asin
Compute the inverse sine of this complex number. Implements the formula:asin(z) = -i (log(sqrt(1 - z<sup>2</sup>) + iz))
Returns
NaN
if either real or imaginary part of the input argument isNaN
or infinite.- Specified by:
asin
in interfaceCalculusFieldElement<Complex>
- Returns:
- the inverse sine of this complex number.
-
atan
Compute the inverse tangent of this complex number. Implements the formula:atan(z) = (i/2) log((1 - iz)/(1 + iz))
Returns
NaN
if either real or imaginary part of the input argument isNaN
or infinite.- Specified by:
atan
in interfaceCalculusFieldElement<Complex>
- Returns:
- the inverse tangent of this complex number
-
cos
Compute the cosine of this complex number. Implements the formula:cos(a + bi) = cos(a)cosh(b) - sin(a)sinh(b)i
where the (real) functions on the right-hand side are
FastMath.sin(double)
,FastMath.cos(double)
,FastMath.cosh(double)
andFastMath.sinh(double)
.Returns
NaN
if either real or imaginary part of the input argument isNaN
.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 ∓ INFINITY i cos(±INFINITY + i) = NaN + NaN i cos(±INFINITY ± INFINITY i) = NaN + NaN i
- Specified by:
cos
in interfaceCalculusFieldElement<Complex>
- Returns:
- the cosine of this complex number.
-
cosh
Compute the hyperbolic cosine of this complex number. Implements the formula:cosh(a + bi) = cosh(a)cos(b) + sinh(a)sin(b)i
FastMath.sin(double)
,FastMath.cos(double)
,FastMath.cosh(double)
andFastMath.sinh(double)
.Returns
Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.NaN
if either real or imaginary part of the input argument isNaN
.Examples:
cosh(1 ± INFINITY i) = NaN + NaN i cosh(±INFINITY + i) = INFINITY ± INFINITY i cosh(±INFINITY ± INFINITY i) = NaN + NaN i
- Specified by:
cosh
in interfaceCalculusFieldElement<Complex>
- Returns:
- the hyperbolic cosine of this complex number.
-
exp
Compute the exponential function of this complex number. Implements the formula:exp(a + bi) = exp(a)cos(b) + exp(a)sin(b)i
FastMath.exp(double)
p},FastMath.cos(double)
, andFastMath.sin(double)
.Returns
Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.NaN
if either real or imaginary part of the input argument isNaN
.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
- Specified by:
exp
in interfaceCalculusFieldElement<Complex>
- Returns:
ethis
.
-
expm1
Exponential minus 1.- Specified by:
expm1
in interfaceCalculusFieldElement<Complex>
- Returns:
- exponential minus one of the instance
- Since:
- 1.7
-
log
Compute the natural logarithm of this complex number. Implements the formula:log(a + bi) = ln(|a + bi|) + arg(a + bi)i
FastMath.log(double)
,|a + bi|
is the modulus,abs()
, andarg(a + bi) =
FastMath.atan2(double, double)
(b, a).Returns
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.NaN
if either real or imaginary part of the input argument isNaN
.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
- Specified by:
log
in interfaceCalculusFieldElement<Complex>
- Returns:
- the value
ln this
, the natural logarithm ofthis
.
-
log1p
Shifted natural logarithm.- Specified by:
log1p
in interfaceCalculusFieldElement<Complex>
- Returns:
- logarithm of one plus the instance
- Since:
- 1.7
-
log10
Base 10 logarithm.- Specified by:
log10
in interfaceCalculusFieldElement<Complex>
- Returns:
- base 10 logarithm of the instance
- Since:
- 1.7
-
pow
Returns of value of this complex number raised to the power ofx
.If
x
is a real number whose real part has an integer value, returnspow(int)
, if boththis
andx
are real andFastMath.pow(double, double)
with the corresponding real arguments would return a finite number (neither NaN nor infinite), then returns the same value converted toComplex
, with the same special cases. In all other cases real cases, implements yx = exp(x·log(y)).- Specified by:
pow
in interfaceCalculusFieldElement<Complex>
- Parameters:
x
- exponent to which thisComplex
is to be raised.- Returns:
thisx
.- Throws:
NullArgumentException
- if x isnull
.
-
pow
Returns of value of this complex number raised to the power ofx
.If
x
has an integer value, returnspow(int)
, ifthis
is real andFastMath.pow(double, double)
with the corresponding real arguments would return a finite number (neither NaN nor infinite), then returns the same value converted toComplex
, with the same special cases. In all other cases real cases, implements yx = exp(x·log(y)).- Specified by:
pow
in interfaceCalculusFieldElement<Complex>
- Parameters:
x
- exponent to which thisComplex
is to be raised.- Returns:
thisx
.
-
pow
Integer power operation.- Specified by:
pow
in interfaceCalculusFieldElement<Complex>
- Parameters:
n
- power to apply- Returns:
- thisn
- Since:
- 1.7
-
sin
Compute the sine of this complex number. Implements the formula:sin(a + bi) = sin(a)cosh(b) + cos(a)sinh(b)i
FastMath.sin(double)
,FastMath.cos(double)
,FastMath.cosh(double)
andFastMath.sinh(double)
.Returns
NaN
if either real or imaginary part of the input argument isNaN
.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
- Specified by:
sin
in interfaceCalculusFieldElement<Complex>
- Returns:
- the sine of this complex number.
-
sinCos
Combined Sine and Cosine operation.- Specified by:
sinCos
in interfaceCalculusFieldElement<Complex>
- Returns:
- [sin(this), cos(this)]
-
atan2
Two arguments arc tangent operation.Beware of the order or arguments! As this is based on a two-arguments functions, in order to be consistent with arguments order, the instance is the first argument and the single provided argument is the second argument. In order to be consistent with programming languages
atan2
, this method computesatan2(this, x)
, i.e. the instance represents they
argument and thex
argument is the one passed as a single argument. This may seem confusing especially for users of Wolfram alpha, as this site is not consistent with programming languagesatan2
two-arguments arc tangent and putsx
as its first argument.- Specified by:
atan2
in interfaceCalculusFieldElement<Complex>
- Parameters:
x
- second argument of the arc tangent- Returns:
- atan2(this, x)
- Since:
- 1.7
-
acosh
Inverse hyperbolic cosine operation.Branch cuts are on the real axis, below +1.
- Specified by:
acosh
in interfaceCalculusFieldElement<Complex>
- Returns:
- acosh(this)
- Since:
- 1.7
-
asinh
Inverse hyperbolic sine operation.Branch cuts are on the imaginary axis, above +i and below -i.
- Specified by:
asinh
in interfaceCalculusFieldElement<Complex>
- Returns:
- asin(this)
- Since:
- 1.7
-
atanh
Inverse hyperbolic tangent operation.Branch cuts are on the real axis, above +1 and below -1.
- Specified by:
atanh
in interfaceCalculusFieldElement<Complex>
- Returns:
- atanh(this)
- Since:
- 1.7
-
sinh
Compute the hyperbolic sine of this complex number. Implements the formula:sinh(a + bi) = sinh(a)cos(b)) + cosh(a)sin(b)i
FastMath.sin(double)
,FastMath.cos(double)
,FastMath.cosh(double)
andFastMath.sinh(double)
.Returns
NaN
if either real or imaginary part of the input argument isNaN
.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
- Specified by:
sinh
in interfaceCalculusFieldElement<Complex>
- Returns:
- the hyperbolic sine of
this
.
-
sinhCosh
Combined hyperbolic sine and cosine operation.- Specified by:
sinhCosh
in interfaceCalculusFieldElement<Complex>
- Returns:
- [sinh(this), cosh(this)]
-
sqrt
Compute the square root of this complex number. Implements the following algorithm to computesqrt(a + bi)
:- Let
t = sqrt((|a| + |a + bi|) / 2)
if
a ≥ 0
returnt + (b/2t)i
else return|b|/2t + sign(b)t i
|a| =
abs(a)
|a + bi| =
hypot(a, b)
sign(b) =
copySign(1, b)
Returns
NaN
if either real or imaginary part of the input argument isNaN
.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 ± ∞ i) = ∞ + NaN i sqrt(∞ + i) = ∞ + 0i sqrt(-∞ + i) = 0 + ∞ i sqrt(∞ ± ∞ i) = ∞ + NaN i sqrt(-∞ ± ∞ i) = NaN ± ∞ i
- Specified by:
sqrt
in interfaceCalculusFieldElement<Complex>
- Returns:
- the square root of
this
with nonnegative real part.
- Let
-
sqrt1z
Compute the square root of1 - this2
for this complex number. Computes the result directly assqrt(ONE.subtract(z.square()))
.Returns
Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.NaN
if either real or imaginary part of the input argument isNaN
.- Returns:
- the square root of
1 - this2
.
-
cbrt
Cubic root.This implementation compute the principal cube root by using a branch cut along real negative axis.
- Specified by:
cbrt
in interfaceCalculusFieldElement<Complex>
- Returns:
- cubic root of the instance
- Since:
- 1.7
-
rootN
Nth root.This implementation compute the principal nth root by using a branch cut along real negative axis.
- Specified by:
rootN
in interfaceCalculusFieldElement<Complex>
- Parameters:
n
- order of the root- Returns:
- nth root of the instance
- Since:
- 1.7
-
tan
Compute the tangent of this complex number. Implements the formula:tan(a + bi) = sin(2a)/(cos(2a)+cosh(2b)) + [sinh(2b)/(cos(2a)+cosh(2b))]i
FastMath.sin(double)
,FastMath.cos(double)
,FastMath.cosh(double)
andFastMath.sinh(double)
.Returns
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.NaN
if either real or imaginary part of the input argument isNaN
.Examples:
tan(a ± INFINITY i) = 0 ± i tan(±INFINITY + bi) = NaN + NaN i tan(±INFINITY ± INFINITY i) = NaN + NaN i tan(±π/2 + 0 i) = ±INFINITY + NaN i
- Specified by:
tan
in interfaceCalculusFieldElement<Complex>
- Returns:
- the tangent of
this
.
-
tanh
Compute the hyperbolic tangent of this complex number. Implements the formula:tan(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]i
FastMath.sin(double)
,FastMath.cos(double)
,FastMath.cosh(double)
andFastMath.sinh(double)
.Returns
Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.NaN
if either real or imaginary part of the input argument isNaN
.Examples:
tanh(a ± INFINITY i) = NaN + NaN i tanh(±INFINITY + bi) = ±1 + 0 i tanh(±INFINITY ± INFINITY i) = NaN + NaN i tanh(0 + (π/2)i) = NaN + INFINITY i
- Specified by:
tanh
in interfaceCalculusFieldElement<Complex>
- Returns:
- the hyperbolic tangent of
this
.
-
getArgument
public double getArgument()Compute the argument of this complex number. The argument is the angle phi between the positive real axis and the point representing this number in the complex plane. The value returned is between -PI (not inclusive) and PI (inclusive), with negative values returned for numbers with negative imaginary parts.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 forMath.atan2
for full details.- Returns:
- the argument of
this
.
-
nthRoot
Computes the n-th roots of this complex number. The nth roots are defined by the formula:zk = abs1/n (cos(phi + 2πk/n) + i (sin(phi + 2πk/n))
k=0, 1, ..., n-1
, whereabs
andphi
are respectively themodulus
andargument
of this complex number.If one or both parts of this complex number is NaN, a list with just one element,
NaN
is returned. if neither part is NaN, but at least one part is infinite, the result is a one-element list containingINF
.- Parameters:
n
- Degree of root.- Returns:
- a List of all
n
-th roots ofthis
. - Throws:
MathIllegalArgumentException
- ifn <= 0
.
-
createComplex
Create a complex number given the real and imaginary parts.- Parameters:
realPart
- Real part.imaginaryPart
- Imaginary part.- Returns:
- a new complex number instance.
- See Also:
-
valueOf
Create a complex number given the real and imaginary parts.- Parameters:
realPart
- Real part.imaginaryPart
- Imaginary part.- Returns:
- a Complex instance.
-
valueOf
Create a complex number given only the real part.- Parameters:
realPart
- Real part.- Returns:
- a Complex instance.
-
newInstance
Create an instance corresponding to a constant real value.- Specified by:
newInstance
in interfaceCalculusFieldElement<Complex>
- Parameters:
realPart
- constant real value- Returns:
- instance corresponding to a constant real value
-
readResolve
Resolve the transient fields in a deserialized Complex Object. Subclasses will need to overridecreateComplex(double, double)
to deserialize properly.- Returns:
- A Complex instance with all fields resolved.
-
getField
Get theField
to which the instance belongs.- Specified by:
getField
in interfaceFieldElement<Complex>
- Returns:
Field
to which the instance belongs
-
toString
-
scalb
Multiply the instance by a power of 2.- Specified by:
scalb
in interfaceCalculusFieldElement<Complex>
- Parameters:
n
- power of 2- Returns:
- this × 2n
- Since:
- 1.7
-
ulp
Compute least significant bit (Unit in Last Position) for a number.- Specified by:
ulp
in interfaceCalculusFieldElement<Complex>
- Returns:
- ulp(this)
-
hypot
Returns the hypotenuse of a triangle with sidesthis
andy
- sqrt(this2 +y2) avoiding intermediate overflow or underflow.- If either argument is infinite, then the result is positive infinity.
- else, if either argument is NaN then the result is NaN.
- Specified by:
hypot
in interfaceCalculusFieldElement<Complex>
- Parameters:
y
- a value- Returns:
- sqrt(this2 +y2)
- Since:
- 1.7
-
linearCombination
Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<Complex>
- Parameters:
a
- Factors.b
- Factors.- Returns:
Σi ai bi
.- Throws:
MathIllegalArgumentException
- if arrays dimensions don't match- Since:
- 1.7
-
linearCombination
Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<Complex>
- Parameters:
a
- Factors.b
- Factors.- Returns:
Σi ai bi
.- Throws:
MathIllegalArgumentException
- if arrays dimensions don't match- Since:
- 1.7
-
linearCombination
Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<Complex>
- Parameters:
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second term- Returns:
- a1×b1 + a2×b2
- Since:
- 1.7
- See Also:
-
linearCombination
Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<Complex>
- Parameters:
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second term- Returns:
- a1×b1 + a2×b2
- Since:
- 1.7
- See Also:
-
linearCombination
public Complex linearCombination(Complex a1, Complex b1, Complex a2, Complex b2, Complex a3, Complex b3) Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<Complex>
- Parameters:
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third term- Returns:
- a1×b1 + a2×b2 + a3×b3
- Since:
- 1.7
- See Also:
-
linearCombination
public Complex linearCombination(double a1, Complex b1, double a2, Complex b2, double a3, Complex b3) Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<Complex>
- Parameters:
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third term- Returns:
- a1×b1 + a2×b2 + a3×b3
- Since:
- 1.7
- See Also:
-
linearCombination
public Complex linearCombination(Complex a1, Complex b1, Complex a2, Complex b2, Complex a3, Complex b3, Complex a4, Complex b4) Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<Complex>
- Parameters:
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third terma4
- first factor of the fourth termb4
- second factor of the fourth term- Returns:
- a1×b1 + a2×b2 + a3×b3 + a4×b4
- Since:
- 1.7
- See Also:
-
linearCombination
public Complex linearCombination(double a1, Complex b1, double a2, Complex b2, double a3, Complex b3, double a4, Complex b4) Compute a linear combination.- Specified by:
linearCombination
in interfaceCalculusFieldElement<Complex>
- Parameters:
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third terma4
- first factor of the fourth termb4
- second factor of the fourth term- Returns:
- a1×b1 + a2×b2 + a3×b3 + a4×b4
- Since:
- 1.7
- See Also:
-
getPi
Get the Archimedes constant π.Archimedes constant is the ratio of a circle's circumference to its diameter.
- Specified by:
getPi
in interfaceCalculusFieldElement<Complex>
- Returns:
- Archimedes constant π
-
ceil
Get the smallest whole number larger than instance.- Specified by:
ceil
in interfaceCalculusFieldElement<Complex>
- Returns:
- ceil(this)
- Since:
- 1.7
-
floor
Get the largest whole number smaller than instance.- Specified by:
floor
in interfaceCalculusFieldElement<Complex>
- Returns:
- floor(this)
- Since:
- 1.7
-
rint
Get the whole number that is the nearest to the instance, or the even one if x is exactly half way between two integers.- Specified by:
rint
in interfaceCalculusFieldElement<Complex>
- Returns:
- a double number r such that r is an integer r - 0.5 ≤ this ≤ r + 0.5
- Since:
- 1.7
-
remainder
IEEE remainder operator.for complex numbers, the integer n corresponding to
this.subtract(remainder(a)).divide(a)
is a Wikipedia - Gaussian integer.- Specified by:
remainder
in interfaceCalculusFieldElement<Complex>
- Parameters:
a
- right hand side parameter of the operator- Returns:
- this - n × a where n is the closest integer to this/a
- Since:
- 1.7
-
remainder
IEEE remainder operator.for complex numbers, the integer n corresponding to
this.subtract(remainder(a)).divide(a)
is a Wikipedia - Gaussian integer.- Specified by:
remainder
in interfaceCalculusFieldElement<Complex>
- Parameters:
a
- right hand side parameter of the operator- Returns:
- this - n × a where n is the closest integer to this/a
- Since:
- 1.7
-
sign
Compute the sign of the instance. The sign is -1 for negative numbers, +1 for positive numbers and 0 otherwise, for Complex number, it is extended on the unit circle (equivalent to z/|z|, with special handling for 0 and NaN)- Specified by:
sign
in interfaceCalculusFieldElement<Complex>
- Returns:
- -1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a
- Since:
- 2.0
-
copySign
Returns the instance with the sign of the argument. A NaNsign
argument is treated as positive.The signs of real and imaginary parts are copied independently.
- Specified by:
copySign
in interfaceCalculusFieldElement<Complex>
- Parameters:
z
- the sign for the returned value- Returns:
- the instance with the same sign as the
sign
argument - Since:
- 1.7
-
copySign
Returns the instance with the sign of the argument. A NaNsign
argument is treated as positive.- Specified by:
copySign
in interfaceCalculusFieldElement<Complex>
- Parameters:
r
- the sign for the returned value- Returns:
- the instance with the same sign as the
sign
argument - Since:
- 1.7
-
toDegrees
Convert radians to degrees, with error of less than 0.5 ULP- Specified by:
toDegrees
in interfaceCalculusFieldElement<Complex>
- Returns:
- instance converted into degrees
-
toRadians
Convert degrees to radians, with error of less than 0.5 ULP- Specified by:
toRadians
in interfaceCalculusFieldElement<Complex>
- Returns:
- instance converted into radians
-
compareTo
Comparison us performed using real ordering as the primary sort order and imaginary ordering as the secondary sort order.
- Specified by:
compareTo
in interfaceComparable<Complex>
- Since:
- 3.0
-