Package fi.iki.jmtilli.javafastcomplex
Class Complex
java.lang.Object
fi.iki.jmtilli.javafastcomplex.Complex
- All Implemented Interfaces:
ComplexNumber,java.io.Serializable
public class Complex extends java.lang.Object implements ComplexNumber, java.io.Serializable
An immutable complex number.
An instance of this class refers to a complex number the value of
which cannot be changed.
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description Complex(double re)Create a complex number with zero imaginary part.Complex(double re, double im)Create a complex number.Complex(ComplexNumber num)Create a complex number that has the same value as the specified other complex number.Complex(ComplexNumberArray num, int i)Create a complex number that has the same value as the specified other complex number. -
Method Summary
Modifier and Type Method Description doubleabs()Calculates the absolute value of this complex number.Complexacos()Calculate the inverse cosine of this complex number.Complexacosh()Calculate the inverse hyperbolic cosine of this complex number.Complexadd(double d)Add a real number to this complex numberComplexadd(ComplexNumber c)Add another complex number to this complex numberComplexadd(ComplexNumberArray c, int i)Add another complex number to this complex numberdoublearg()Calculates the argument of this complex number.Complexasin()Calculate the inverse sine of this complex number.Complexasinh()Calculate the inverse hyperbolic sine of this complex number.Complexatan()Calculate the inverse tangent of this complex number.Complexatanh()Calculate the inverse hyperbolic tangent of this complex number.Complexconjugate()Calculates the conjugate of this complex numberComplexcos()Calculate the cosine of this complex number.Complexcosh()Calculate the hyperbolic cosine of this complex number.Complexdivide(double d)Divide this complex number by a real numberComplexdivide(ComplexNumber c)Divide this complex number by another complex numberComplexdivide(ComplexNumberArray c, int i)Divide this complex number by another complex numberComplexdivideReversed(double d)Divide a real number by this complex numberComplexdivideReversed(ComplexNumber c)Divide another complex number by this complex numberComplexdivideReversed(ComplexNumberArray c, int i)Divide another complex number by this complex numberbooleanequals(java.lang.Object o)Compare this complex number to another object.Complexexp()Calculates the exponential of this complex numberComplexexpm1()Returns exp(this)-1.doublegetImag()Returns the imaginary part of the complex number.doublegetReal()Returns the real part of the complex number.inthashCode()Returns a hash code of the complex number.Complexinvert()Calculates the inverse of this complex numberbooleanisInfinite()Check whether the complex number is infinite.booleanisNaN()Check whether the complex number is NaN (not-a-numer).Complexlog()Calculates the natural logarithm of this complex numberComplexlog1p()Returns log(this+1).Complexmultiply(double d)Multiply this complex number by a real numberComplexmultiply(int i)Multiply this complex number by an integerComplexmultiply(ComplexNumber c)Multiply this complex number by another complex numberComplexmultiply(ComplexNumberArray c, int i)Multiply this complex number by another complex numberComplexnegate()Calculates the negation of this complex numberstatic ComplexnewPolar(double abs, double argument)Create a complex number from polar coordinates.Complexpow(double d)Raise this complex number to a real powerComplexpow(ComplexNumber c)Raise this complex number to a complex powerComplexpow(ComplexNumberArray c, int i)Raise this complex number to a complex powerComplexsin()Calculate the sine of this complex number.Complexsinh()Calculate the hyperbolic sine of this complex number.Complexsqrt()Calculates the square root of this complex numberComplexsubtract(double d)Subtract a real number from this complex numberComplexsubtract(ComplexNumber c)Subtract another complex number from this complex numberComplexsubtract(ComplexNumberArray c, int i)Subtract another complex number from this complex numberComplexsubtractReversed(double d)Subtract this complex number from a real numberComplexsubtractReversed(ComplexNumber c)Subtract this complex number from another complex numberComplexsubtractReversed(ComplexNumberArray c, int i)Subtract this complex number from another complex numberComplextan()Calculate the tangent of this complex number.Complextanh()Calculate the hyperbolic tangent of this complex number.java.lang.StringtoString()Returns a text representation of the complex number.static ComplexvalueOf(double re)Create a complex number with zero imaginary part.static ComplexvalueOf(double re, double im)Create a complex number.static ComplexvalueOf(ComplexNumber num)Create a complex number that has the same value as the specified other complex number.static ComplexvalueOf(ComplexNumberArray num, int i)Create a complex number that has the same value as the specified other complex number.
-
Field Details
-
Constructor Details
-
Complex
Create a complex number that has the same value as the specified other complex number.- Parameters:
num- The other complex number
-
Complex
Create a complex number that has the same value as the specified other complex number.- Parameters:
num- The other complex number arrayi- Array index
-
Complex
public Complex(double re)Create a complex number with zero imaginary part.- Parameters:
re- The real part
-
Complex
public Complex(double re, double im)Create a complex number.- Parameters:
re- The real partim- The imaginary part
-
-
Method Details
-
valueOf
Create a complex number that has the same value as the specified other complex number. If a new Complex instance is not required, this method should be used instead of the constructor Complex(ComplexNumber), as this method results in better performance by caching frequently used values.- Parameters:
num- The other complex number- Returns:
- The new complex number
-
valueOf
Create a complex number that has the same value as the specified other complex number. If a new Complex instance is not required, this method should be used instead of the constructor Complex(ComplexNumber), as this method results in better performance by caching frequently used values.- Parameters:
num- The other complex number arrayi- Array index- Returns:
- The new complex number
-
valueOf
Create a complex number with zero imaginary part. If a new Complex instance is not required, this method should be used instead of the constructor Complex(double), as this method results in better performance by caching frequently used values.- Parameters:
re- The real part- Returns:
- The new complex number
-
valueOf
Create a complex number. If a new Complex instance is not required, this method should be used instead of the constructor Complex(double, double), as this method results in better performance by caching frequently used values.- Parameters:
re- The real partim- The imaginary part- Returns:
- The new complex number
-
newPolar
Create a complex number from polar coordinates.- Parameters:
abs- The absolute valueargument- The argument- Returns:
- The new complex number
-
getReal
public double getReal()Returns the real part of the complex number.- Specified by:
getRealin interfaceComplexNumber- Returns:
- The real part
-
getImag
public double getImag()Returns the imaginary part of the complex number.- Specified by:
getImagin interfaceComplexNumber- Returns:
- The imaginary part
-
add
Add another complex number to this complex number- Parameters:
c- The other complex number- Returns:
- the sum
-
add
Add another complex number to this complex number- Parameters:
c- The other complex number arrayi- The array index- Returns:
- the sum
-
add
Add a real number to this complex number- Parameters:
d- The real number- Returns:
- the sum
-
subtract
Subtract another complex number from this complex number- Parameters:
c- The other complex number- Returns:
- the difference
-
subtract
Subtract another complex number from this complex number- Parameters:
c- The other complex number arrayi- The array index- Returns:
- the difference
-
subtractReversed
Subtract this complex number from another complex number- Parameters:
c- The other complex number- Returns:
- the difference
-
subtractReversed
Subtract this complex number from another complex number- Parameters:
c- The other complex number arrayi- The array index- Returns:
- the difference
-
subtract
Subtract a real number from this complex number- Parameters:
d- The real number- Returns:
- the difference
-
subtractReversed
Subtract this complex number from a real number- Parameters:
d- The real number- Returns:
- the difference
-
multiply
Multiply this complex number by another complex number- Parameters:
c- The complex number multiplier- Returns:
- the product
-
multiply
Multiply this complex number by another complex number- Parameters:
c- The complex number array multiplieri- The array index- Returns:
- the product
-
multiply
Multiply this complex number by a real number- Parameters:
d- The real number multiplier- Returns:
- the product
-
multiply
Multiply this complex number by an integer- Parameters:
i- The integer multiplier- Returns:
- the product
-
divide
Divide this complex number by another complex number- Parameters:
c- The complex number divisor- Returns:
- the result of this division
-
divide
Divide this complex number by another complex number- Parameters:
c- The complex number array divisori- The array index- Returns:
- the result of this division
-
divide
Divide this complex number by a real number- Parameters:
d- The real number divisor- Returns:
- the result of this division
-
divideReversed
Divide another complex number by this complex number- Parameters:
c- The complex number dividend- Returns:
- the result of this division
-
divideReversed
Divide another complex number by this complex number- Parameters:
c- The complex number array dividendi- The array index- Returns:
- the result of this division
-
divideReversed
Divide a real number by this complex number- Parameters:
d- The real number dividend- Returns:
- the result of this division
-
negate
Calculates the negation of this complex number- Returns:
- -this
-
conjugate
Calculates the conjugate of this complex number- Returns:
- The square root
-
sqrt
Calculates the square root of this complex number- Returns:
- The square root
-
exp
Calculates the exponential of this complex number- Returns:
- e raised to the power this
-
expm1
Returns exp(this)-1. For values of this near 0, calculating expm1(this) is much more accurate than calculating exp(this)-1.- Returns:
- The value exp(this)-1
-
log
Calculates the natural logarithm of this complex number- Returns:
- The natural logarithm
-
log1p
Returns log(this+1). For values of this near 0, calculating log1p(this) is much more accurate than calculating log(1+this).- Returns:
- The value log(1+this)
-
acosh
Calculate the inverse hyperbolic cosine of this complex number.- Returns:
- The inverse hyperbolic cosine of this complex number
-
asinh
Calculate the inverse hyperbolic sine of this complex number.- Returns:
- The inverse hyperbolic sine of this complex number
-
atanh
Calculate the inverse hyperbolic tangent of this complex number.- Returns:
- The inverse hyperbolic tangent of this complex number
-
acos
Calculate the inverse cosine of this complex number.- Returns:
- The inverse cosine of this complex number
-
asin
Calculate the inverse sine of this complex number.- Returns:
- The inverse sine of this complex number
-
atan
Calculate the inverse tangent of this complex number.- Returns:
- The inverse tangent of this complex number
-
cos
Calculate the cosine of this complex number.- Returns:
- The cosine of this complex number
-
sin
Calculate the sine of this complex number.- Returns:
- The sine of this complex number
-
tan
Calculate the tangent of this complex number.- Returns:
- The tangent of this complex number
-
cosh
Calculate the hyperbolic cosine of this complex number.- Returns:
- The hyperbolic cosine of this complex number
-
sinh
Calculate the hyperbolic sine of this complex number.- Returns:
- The hyperbolic sine of this complex number
-
tanh
Calculate the hyperbolic tangent of this complex number.- Returns:
- The hyperbolic tangent of this complex number
-
pow
Raise this complex number to a complex power- Parameters:
c- The complex power- Returns:
- The result
-
pow
Raise this complex number to a complex power- Parameters:
c- The complex array poweri- The array index- Returns:
- The result
-
pow
Raise this complex number to a real power- Parameters:
d- The real power- Returns:
- The result
-
invert
Calculates the inverse of this complex number- Returns:
- 1 divided by this complex number
-
abs
public double abs()Calculates the absolute value of this complex number.- Specified by:
absin interfaceComplexNumber- Returns:
- x≥0 the absolute value
-
arg
public double arg()Calculates the argument of this complex number. The argument is the angle between the positive real axis and the point that represents this number in the complex plane.- Specified by:
argin interfaceComplexNumber- Returns:
- -pi≤x≤pi the argument
-
isNaN
public boolean isNaN()Check whether the complex number is NaN (not-a-numer). A complex number is considered NaN if either the real or the imaginary part is NaN.- Specified by:
isNaNin interfaceComplexNumber- Returns:
- Whether the complex number is NaN
-
isInfinite
public boolean isInfinite()Check whether the complex number is infinite. A complex number is considered infinite if either the real or the imaginary part is infinite. If either the real of imaginary part is NaN, the number is not considered infinite, so isNaN() and isInfinite() cannot be true at the same time.- Specified by:
isInfinitein interfaceComplexNumber- Returns:
- Whether the complex number is infinite
-
toString
public java.lang.String toString()Returns a text representation of the complex number.- Specified by:
toStringin interfaceComplexNumber- Overrides:
toStringin classjava.lang.Object- Returns:
- A text representation of the complex number.
"NaN" if NaN
re if purely real
im + "i" if purely imaginary
re " + " + im + "i" if imaginary part positive
re " - " + (-im) + "i" if imaginary part negative
-
hashCode
public int hashCode()Returns a hash code of the complex number. The hash code is based on the bit representations of the real and imaginary parts. If two complex numbers are considered equal by the equals method, they have the same hash code. The hash code calculation is the same as ComplexUtils.hashCode.- Overrides:
hashCodein classjava.lang.Object- Returns:
- The hash code
-
equals
public boolean equals(java.lang.Object o)Compare this complex number to another object. Note that this compares the bit representations of the real and imaginary parts. Thus for example NaN is equal to itself and +0.0+0.0i is not equal to -0.0-0.0i. All instances of NaN are considered equal. This definition allows hash tables to work properly. The equality comparison is the same as ComplexUtils.equal.- Overrides:
equalsin classjava.lang.Object- Returns:
- true if both complex numbers are NaN
true if the bit representations of the real and imaginary parts are equal
false if o is not an instance of the Complex class
false otherwise
-