public final class BigComplex
extends java.lang.Object
BigDecimal part in the form a + bi.
It generally follows the design of BigDecimal with some convenience improvements like overloaded operator methods.
The biggest difference to BigDecimal is that BigComplex.equals(Object) implements the mathematical equality
and not the strict technical equality.
This was a difficult decision because it means that BigComplex behaves slightly different than BigDecimal
but considering that the strange equality of BigDecimal is a major source of bugs we
decided it was worth the slight inconsistency.
If you need the strict equality use strictEquals(Object)`.
This class is immutable and therefore inherently thread safe.
| Modifier and Type | Field and Description |
|---|---|
static BigComplex |
I
Imaginary 1 represented as complex number.
|
java.math.BigDecimal |
im
The imaginary
BigDecimal part of this complex number. |
static BigComplex |
ONE
Real 1 represented as complex number.
|
java.math.BigDecimal |
re
The real
BigDecimal part of this complex number. |
static BigComplex |
ZERO
Zero represented as complex number.
|
| Modifier and Type | Method and Description |
|---|---|
java.math.BigDecimal |
abs(java.math.MathContext mathContext)
Calculates the absolute value (also known as magnitude, length or radius) of this complex number.
|
java.math.BigDecimal |
absSquare(java.math.MathContext mathContext)
Calculates the square of the absolute value of this complex number.
|
BigComplex |
add(BigComplex value)
Calculates the addition of the given complex value to this complex number.
|
BigComplex |
add(BigComplex value,
java.math.MathContext mathContext)
Calculates the addition of the given complex value to this complex number using the specified
MathContext. |
BigComplex |
add(java.math.BigDecimal value)
Calculates the addition of the given real
BigDecimal value to this complex number. |
BigComplex |
add(java.math.BigDecimal value,
java.math.MathContext mathContext)
Calculates the addition of the given real
BigDecimal value to this complex number using the specified MathContext. |
BigComplex |
add(double value)
Calculates the addition of the given real
double value to this complex number. |
java.math.BigDecimal |
angle(java.math.MathContext mathContext)
Calculates the angle in radians (also known as argument) of this complex number.
|
BigComplex |
conjugate()
Calculates the conjugate
a - bi of this complex number. |
BigComplex |
divide(BigComplex value,
java.math.MathContext mathContext)
Calculates this complex number divided by the given complex value using the specified
MathContext. |
BigComplex |
divide(java.math.BigDecimal value,
java.math.MathContext mathContext)
Calculates this complex number divided by the given real
BigDecimal value using the specified MathContext. |
BigComplex |
divide(double value,
java.math.MathContext mathContext)
Calculates this complex number divided by the given real
double value using the specified MathContext. |
boolean |
equals(java.lang.Object obj) |
int |
hashCode() |
BigComplex |
im()
Returns the imaginary part of this complex number as
BigComplex number. |
boolean |
isReal()
Returns whether this complex number only has a real part (the imaginary part is 0).
|
BigComplex |
multiply(BigComplex value)
Calculates the multiplication of the given complex value to this complex number.
|
BigComplex |
multiply(BigComplex value,
java.math.MathContext mathContext)
Calculates the multiplication of the given complex value with this complex number using the specified
MathContext. |
BigComplex |
multiply(java.math.BigDecimal value)
Calculates the multiplication of the given real
BigDecimal value with this complex number. |
BigComplex |
multiply(java.math.BigDecimal value,
java.math.MathContext mathContext)
Calculates the multiplication of the given real
BigDecimal value with this complex number using the specified MathContext. |
BigComplex |
multiply(double value)
Calculates the multiplication of the given real
double value with this complex number. |
BigComplex |
negate()
Calculates the negation
-a - bi of this complex number. |
BigComplex |
re()
Returns the real part of this complex number as
BigComplex number. |
BigComplex |
reciprocal(java.math.MathContext mathContext)
Calculates the reciprocal of this complex number using the specified
MathContext. |
BigComplex |
round(java.math.MathContext mathContext)
Returns this complex nuber rounded to the specified precision.
|
boolean |
strictEquals(java.lang.Object obj)
Returns whether the real and imaginary parts of this complex number are strictly equal.
|
BigComplex |
subtract(BigComplex value)
Calculates the subtraction of the given complex value from this complex number.
|
BigComplex |
subtract(BigComplex value,
java.math.MathContext mathContext)
Calculates the subtraction of the given complex value from this complex number using the specified
MathContext. |
BigComplex |
subtract(java.math.BigDecimal value)
Calculates the subtraction of the given real
BigDecimal value from this complex number. |
BigComplex |
subtract(java.math.BigDecimal value,
java.math.MathContext mathContext)
Calculates the subtraction of the given real
BigDecimal value from this complex number using the specified MathContext. |
BigComplex |
subtract(double value)
Calculates the subtraction of the given real
double value from this complex number. |
java.lang.String |
toString() |
static BigComplex |
valueOf(java.math.BigDecimal real)
Returns a complex number with the specified real
BigDecimal part. |
static BigComplex |
valueOf(java.math.BigDecimal real,
java.math.BigDecimal imaginary)
Returns a complex number with the specified real and imaginary
BigDecimal parts. |
static BigComplex |
valueOf(double real)
Returns a complex number with the specified real
double part. |
static BigComplex |
valueOf(double real,
double imaginary)
Returns a complex number with the specified real and imaginary
double parts. |
static BigComplex |
valueOfPolar(java.math.BigDecimal radius,
java.math.BigDecimal angle,
java.math.MathContext mathContext)
Returns a complex number with the specified polar
BigDecimal radius and angle using the specified MathContext. |
static BigComplex |
valueOfPolar(double radius,
double angle,
java.math.MathContext mathContext) |
public static final BigComplex ZERO
public static final BigComplex ONE
public static final BigComplex I
public final java.math.BigDecimal re
BigDecimal part of this complex number.public final java.math.BigDecimal im
BigDecimal part of this complex number.public BigComplex add(BigComplex value)
This methods does not modify this instance.
value - the BigComplex value to addBigComplex resultpublic BigComplex add(BigComplex value, java.math.MathContext mathContext)
MathContext.
This methods does not modify this instance.
value - the BigComplex value to addmathContext - the MathContext used to calculate the resultBigComplex resultpublic BigComplex add(java.math.BigDecimal value, java.math.MathContext mathContext)
BigDecimal value to this complex number using the specified MathContext.
This methods does not modify this instance.
value - the real BigDecimal value to addmathContext - the MathContext used to calculate the resultBigComplex resultpublic BigComplex add(java.math.BigDecimal value)
BigDecimal value to this complex number.
This methods does not modify this instance.
value - the real BigDecimal value to addBigComplex resultpublic BigComplex add(double value)
double value to this complex number.
This methods does not modify this instance.
value - the real double value to addBigComplex resultpublic BigComplex subtract(BigComplex value)
This methods does not modify this instance.
value - the BigComplex value to subtractBigComplex resultpublic BigComplex subtract(BigComplex value, java.math.MathContext mathContext)
MathContext.
This methods does not modify this instance.
value - the BigComplex value to subtractmathContext - the MathContext used to calculate the resultBigComplex resultpublic BigComplex subtract(java.math.BigDecimal value, java.math.MathContext mathContext)
BigDecimal value from this complex number using the specified MathContext.
This methods does not modify this instance.
value - the real BigDecimal value to addmathContext - the MathContext used to calculate the resultBigComplex resultpublic BigComplex subtract(java.math.BigDecimal value)
BigDecimal value from this complex number.
This methods does not modify this instance.
value - the real BigDecimal value to subtractBigComplex resultpublic BigComplex subtract(double value)
double value from this complex number.
This methods does not modify this instance.
value - the real double value to subtractBigComplex resultpublic BigComplex multiply(BigComplex value)
This methods does not modify this instance.
value - the BigComplex value to multiplyBigComplex resultpublic BigComplex multiply(BigComplex value, java.math.MathContext mathContext)
MathContext.
This methods does not modify this instance.
value - the BigComplex value to multiplymathContext - the MathContext used to calculate the resultBigComplex resultpublic BigComplex multiply(java.math.BigDecimal value, java.math.MathContext mathContext)
BigDecimal value with this complex number using the specified MathContext.
This methods does not modify this instance.
value - the real BigDecimal value to multiplymathContext - the MathContext used to calculate the resultBigComplex resultpublic BigComplex multiply(java.math.BigDecimal value)
BigDecimal value with this complex number.
This methods does not modify this instance.
value - the real BigDecimal value to multiplyBigComplex resultpublic BigComplex multiply(double value)
double value with this complex number.
This methods does not modify this instance.
value - the real double value to multiplyBigComplex resultpublic BigComplex divide(BigComplex value, java.math.MathContext mathContext)
MathContext.
This methods does not modify this instance.
value - the BigComplex value to divide bymathContext - the MathContext used to calculate the resultBigComplex resultpublic BigComplex divide(java.math.BigDecimal value, java.math.MathContext mathContext)
BigDecimal value using the specified MathContext.
This methods does not modify this instance.
value - the BigDecimal value to divide bymathContext - the MathContext used to calculate the resultBigComplex resultpublic BigComplex divide(double value, java.math.MathContext mathContext)
double value using the specified MathContext.
This methods does not modify this instance.
value - the double value to divide bymathContext - the MathContext used to calculate the resultBigComplex resultpublic BigComplex reciprocal(java.math.MathContext mathContext)
MathContext.
This methods does not modify this instance.
mathContext - the MathContext used to calculate the resultBigComplex resultpublic BigComplex conjugate()
a - bi of this complex number.
This methods does not modify this instance.
BigComplex resultpublic BigComplex negate()
-a - bi of this complex number.
This methods does not modify this instance.
BigComplex resultpublic java.math.BigDecimal abs(java.math.MathContext mathContext)
This method is slower than absSquare(MathContext) since it needs to calculate the BigDecimalMath.sqrt(BigDecimal, MathContext).
This methods does not modify this instance.
mathContext - the MathContext used to calculate the resultBigComplex resultabsSquare(MathContext)public java.math.BigDecimal angle(java.math.MathContext mathContext)
This methods does not modify this instance.
mathContext - the MathContext used to calculate the resultBigComplex resultpublic java.math.BigDecimal absSquare(java.math.MathContext mathContext)
This method is faster than abs(MathContext) since it does not need to calculate the BigDecimalMath.sqrt(BigDecimal, MathContext).
This methods does not modify this instance.
mathContext - the MathContext used to calculate the resultBigComplex resultabs(MathContext)public boolean isReal()
true if this complex number only has a real part, false if the imaginary part is not 0public BigComplex re()
BigComplex number.BigComplex numberpublic BigComplex im()
BigComplex number.BigComplex numberpublic BigComplex round(java.math.MathContext mathContext)
This methods does not modify this instance.
mathContext - the MathContext used to calculate the resultBigComplex resultpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
Contrary to BigDecimal.equals(Object) this method implements mathematical equality
(by calling BigDecimal.compareTo(BigDecimal) on the real and imaginary parts)
instead of strict equality.
equals in class java.lang.ObjectstrictEquals(Object)public boolean strictEquals(java.lang.Object obj)
This method uses the strict equality as defined by BigDecimal.equals(Object) on the real and imaginary parts.
Please note that BigComplex.equals(Object) implements mathematical equality instead
(by calling on the real and imaginary parts).
obj - the object to compare for strict equalitytrue if the specified object is strictly equal to this complex numberequals(Object)public java.lang.String toString()
toString in class java.lang.Objectpublic static BigComplex valueOf(java.math.BigDecimal real)
BigDecimal part.real - the real BigDecimal partpublic static BigComplex valueOf(double real)
double part.real - the real double partpublic static BigComplex valueOf(double real, double imaginary)
double parts.real - the real double partimaginary - the imaginary double partpublic static BigComplex valueOf(java.math.BigDecimal real, java.math.BigDecimal imaginary)
BigDecimal parts.real - the real BigDecimal partimaginary - the imaginary BigDecimal partpublic static BigComplex valueOfPolar(java.math.BigDecimal radius, java.math.BigDecimal angle, java.math.MathContext mathContext)
BigDecimal radius and angle using the specified MathContext.radius - the BigDecimal radius of the polar representationangle - the BigDecimal angle in radians of the polar representationmathContext - the MathContext used to calculate the resultpublic static BigComplex valueOfPolar(double radius, double angle, java.math.MathContext mathContext)