Class BigComplex
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BigComplexImaginary 1 represented as complex number.final BigDecimalThe imaginaryBigDecimalpart of this complex number.static final BigComplexReal 1 represented as complex number.final BigDecimalThe realBigDecimalpart of this complex number.static final BigComplexZero represented as complex number. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs(MathContext mathContext) Calculates the absolute value (also known as magnitude, length or radius) of this complex number.absSquare(MathContext mathContext) Calculates the square of the absolute value of this complex number.add(double value) Calculates the addition of the given realdoublevalue to this complex number.add(BigComplex value) Calculates the addition of the given complex value to this complex number.add(BigComplex value, MathContext mathContext) Calculates the addition of the given complex value to this complex number using the specifiedMathContext.add(BigDecimal value) Calculates the addition of the given realBigDecimalvalue to this complex number.add(BigDecimal value, MathContext mathContext) Calculates the addition of the given realBigDecimalvalue to this complex number using the specifiedMathContext.angle(MathContext mathContext) Calculates the angle in radians (also known as argument) of this complex number.Calculates the conjugatea - biof this complex number.divide(double value, MathContext mathContext) Calculates this complex number divided by the given realdoublevalue using the specifiedMathContext.divide(BigComplex value, MathContext mathContext) Calculates this complex number divided by the given complex value using the specifiedMathContext.divide(BigDecimal value, MathContext mathContext) Calculates this complex number divided by the given realBigDecimalvalue using the specifiedMathContext.booleaninthashCode()im()Returns the imaginary part of this complex number asBigComplexnumber.booleanisReal()Returns whether this complex number only has a real part (the imaginary part is 0).multiply(double value) Calculates the multiplication of the given realdoublevalue with this complex number.multiply(BigComplex value) Calculates the multiplication of the given complex value to this complex number.multiply(BigComplex value, MathContext mathContext) Calculates the multiplication of the given complex value with this complex number using the specifiedMathContext.multiply(BigDecimal value) Calculates the multiplication of the given realBigDecimalvalue with this complex number.multiply(BigDecimal value, MathContext mathContext) Calculates the multiplication of the given realBigDecimalvalue with this complex number using the specifiedMathContext.negate()Calculates the negation-a - biof this complex number.re()Returns the real part of this complex number asBigComplexnumber.reciprocal(MathContext mathContext) Calculates the reciprocal of this complex number using the specifiedMathContext.round(MathContext mathContext) Returns this complex nuber rounded to the specified precision.booleanstrictEquals(Object obj) Returns whether the real and imaginary parts of this complex number are strictly equal.subtract(double value) Calculates the subtraction of the given realdoublevalue from this complex number.subtract(BigComplex value) Calculates the subtraction of the given complex value from this complex number.subtract(BigComplex value, MathContext mathContext) Calculates the subtraction of the given complex value from this complex number using the specifiedMathContext.subtract(BigDecimal value) Calculates the subtraction of the given realBigDecimalvalue from this complex number.subtract(BigDecimal value, MathContext mathContext) Calculates the subtraction of the given realBigDecimalvalue from this complex number using the specifiedMathContext.toString()static BigComplexvalueOf(double real) Returns a complex number with the specified realdoublepart.static BigComplexvalueOf(double real, double imaginary) Returns a complex number with the specified real and imaginarydoubleparts.static BigComplexvalueOf(BigDecimal real) Returns a complex number with the specified realBigDecimalpart.static BigComplexvalueOf(BigDecimal real, BigDecimal imaginary) Returns a complex number with the specified real and imaginaryBigDecimalparts.static BigComplexvalueOfPolar(double radius, double angle, MathContext mathContext) static BigComplexvalueOfPolar(BigDecimal radius, BigDecimal angle, MathContext mathContext) Returns a complex number with the specified polarBigDecimalradius and angle using the specifiedMathContext.
-
Field Details
-
ZERO
Zero represented as complex number. -
ONE
Real 1 represented as complex number. -
I
Imaginary 1 represented as complex number. -
re
The realBigDecimalpart of this complex number. -
im
The imaginaryBigDecimalpart of this complex number.
-
-
Constructor Details
-
BigComplex
-
-
Method Details
-
add
Calculates the addition of the given complex value to this complex number.This methods does not modify this instance.
- Parameters:
value- theBigComplexvalue to add- Returns:
- the calculated
BigComplexresult
-
add
Calculates the addition of the given complex value to this complex number using the specifiedMathContext.This methods does not modify this instance.
- Parameters:
value- theBigComplexvalue to addmathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult
-
add
Calculates the addition of the given realBigDecimalvalue to this complex number using the specifiedMathContext.This methods does not modify this instance.
- Parameters:
value- the realBigDecimalvalue to addmathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult
-
add
Calculates the addition of the given realBigDecimalvalue to this complex number.This methods does not modify this instance.
- Parameters:
value- the realBigDecimalvalue to add- Returns:
- the calculated
BigComplexresult
-
add
Calculates the addition of the given realdoublevalue to this complex number.This methods does not modify this instance.
- Parameters:
value- the realdoublevalue to add- Returns:
- the calculated
BigComplexresult
-
subtract
Calculates the subtraction of the given complex value from this complex number.This methods does not modify this instance.
- Parameters:
value- theBigComplexvalue to subtract- Returns:
- the calculated
BigComplexresult
-
subtract
Calculates the subtraction of the given complex value from this complex number using the specifiedMathContext.This methods does not modify this instance.
- Parameters:
value- theBigComplexvalue to subtractmathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult
-
subtract
Calculates the subtraction of the given realBigDecimalvalue from this complex number using the specifiedMathContext.This methods does not modify this instance.
- Parameters:
value- the realBigDecimalvalue to addmathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult
-
subtract
Calculates the subtraction of the given realBigDecimalvalue from this complex number.This methods does not modify this instance.
- Parameters:
value- the realBigDecimalvalue to subtract- Returns:
- the calculated
BigComplexresult
-
subtract
Calculates the subtraction of the given realdoublevalue from this complex number.This methods does not modify this instance.
- Parameters:
value- the realdoublevalue to subtract- Returns:
- the calculated
BigComplexresult
-
multiply
Calculates the multiplication of the given complex value to this complex number.This methods does not modify this instance.
- Parameters:
value- theBigComplexvalue to multiply- Returns:
- the calculated
BigComplexresult
-
multiply
Calculates the multiplication of the given complex value with this complex number using the specifiedMathContext.This methods does not modify this instance.
- Parameters:
value- theBigComplexvalue to multiplymathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult
-
multiply
Calculates the multiplication of the given realBigDecimalvalue with this complex number using the specifiedMathContext.This methods does not modify this instance.
- Parameters:
value- the realBigDecimalvalue to multiplymathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult
-
multiply
Calculates the multiplication of the given realBigDecimalvalue with this complex number.This methods does not modify this instance.
- Parameters:
value- the realBigDecimalvalue to multiply- Returns:
- the calculated
BigComplexresult
-
multiply
Calculates the multiplication of the given realdoublevalue with this complex number.This methods does not modify this instance.
- Parameters:
value- the realdoublevalue to multiply- Returns:
- the calculated
BigComplexresult
-
divide
Calculates this complex number divided by the given complex value using the specifiedMathContext.This methods does not modify this instance.
- Parameters:
value- theBigComplexvalue to divide bymathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult
-
divide
Calculates this complex number divided by the given realBigDecimalvalue using the specifiedMathContext.This methods does not modify this instance.
- Parameters:
value- theBigDecimalvalue to divide bymathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult
-
divide
Calculates this complex number divided by the given realdoublevalue using the specifiedMathContext.This methods does not modify this instance.
- Parameters:
value- thedoublevalue to divide bymathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult
-
reciprocal
Calculates the reciprocal of this complex number using the specifiedMathContext.This methods does not modify this instance.
- Parameters:
mathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult
-
conjugate
Calculates the conjugatea - biof this complex number.This methods does not modify this instance.
- Returns:
- the calculated
BigComplexresult
-
negate
Calculates the negation-a - biof this complex number.This methods does not modify this instance.
- Returns:
- the calculated
BigComplexresult
-
abs
Calculates the absolute value (also known as magnitude, length or radius) of this complex number.This method is slower than
absSquare(MathContext)since it needs to calculate theBigDecimalMath.sqrt(BigDecimal, MathContext).This methods does not modify this instance.
- Parameters:
mathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult - See Also:
-
angle
Calculates the angle in radians (also known as argument) of this complex number.This methods does not modify this instance.
- Parameters:
mathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult
-
absSquare
Calculates the square of the absolute value of this complex number.This method is faster than
abs(MathContext)since it does not need to calculate theBigDecimalMath.sqrt(BigDecimal, MathContext).This methods does not modify this instance.
- Parameters:
mathContext- theMathContextused to calculate the result- Returns:
- the calculated
BigComplexresult - See Also:
-
isReal
public boolean isReal()Returns whether this complex number only has a real part (the imaginary part is 0).- Returns:
trueif this complex number only has a real part,falseif the imaginary part is not 0
-
re
Returns the real part of this complex number asBigComplexnumber.- Returns:
- the real part as as
BigComplexnumber
-
im
Returns the imaginary part of this complex number asBigComplexnumber.- Returns:
- the imaginary part as as
BigComplexnumber
-
round
Returns this complex nuber rounded to the specified precision.This methods does not modify this instance.
- Parameters:
mathContext- theMathContextused to calculate the result- Returns:
- the rounded
BigComplexresult
-
hashCode
public int hashCode() -
equals
Contrary to
BigDecimal.equals(Object)this method implements mathematical equality (by callingBigDecimal.compareTo(BigDecimal)on the real and imaginary parts) instead of strict equality. -
strictEquals
Returns whether the real and imaginary parts of this complex number are strictly equal.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 callingon the real and imaginary parts).- Parameters:
obj- the object to compare for strict equality- Returns:
trueif the specified object is strictly equal to this complex number- See Also:
-
toString
-
valueOf
Returns a complex number with the specified realBigDecimalpart.- Parameters:
real- the realBigDecimalpart- Returns:
- the complex number
-
valueOf
Returns a complex number with the specified realdoublepart.- Parameters:
real- the realdoublepart- Returns:
- the complex number
-
valueOf
Returns a complex number with the specified real and imaginarydoubleparts.- Parameters:
real- the realdoublepartimaginary- the imaginarydoublepart- Returns:
- the complex number
-
valueOf
Returns a complex number with the specified real and imaginaryBigDecimalparts.- Parameters:
real- the realBigDecimalpartimaginary- the imaginaryBigDecimalpart- Returns:
- the complex number
-
valueOfPolar
Returns a complex number with the specified polarBigDecimalradius and angle using the specifiedMathContext.- Parameters:
radius- theBigDecimalradius of the polar representationangle- theBigDecimalangle in radians of the polar representationmathContext- theMathContextused to calculate the result- Returns:
- the complex number
-
valueOfPolar
-