cc.redberry.core.number
Class Complex
- java.lang.Object
-
- cc.redberry.core.tensor.Tensor
-
- cc.redberry.core.number.Complex
-
- All Implemented Interfaces:
- Number<Complex>, java.io.Serializable, java.lang.Comparable<Tensor>, java.lang.Iterable<Tensor>, org.apache.commons.math3.FieldElement<Complex>
public final class Complex extends Tensor implements Number<Complex>, java.io.Serializable
Implementation of complex numbers.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static ComplexCOMPLEX_INFINITYstatic ComplexCOMPLEX_NEGATIVE_INFINITYstatic ComplexCOMPLEX_POSITIVE_INFINITYstatic ComplexComplexNaNstatic ComplexFOURstatic ComplexIMAGINARY_NEGATIVE_INFINITYstatic ComplexIMAGINARY_POSITIVE_INFINITYstatic ComplexIMAGINARY_UNITstatic ComplexMINUS_ONEstatic ComplexMINUS_ONE_HALFstatic ComplexMINUS_TWOstatic ComplexNEGATIVE_IMAGINARY_UNITstatic ComplexONEstatic ComplexONE_HALFstatic ComplexREAL_NEGATIVE_INFINITYstatic ComplexREAL_POSITIVE_INFINITYstatic ComplexTWOstatic ComplexZERO
-
Constructor Summary
Constructors Constructor and Description Complex(java.math.BigInteger real)Complex(java.math.BigInteger real, java.math.BigInteger imaginary)Complex(org.apache.commons.math3.complex.Complex complex)Complex(double real)Complex(double real, double imaginary)Complex(double real, int imaginary)Complex(int real)Complex(int real, double imaginary)Complex(int real, int imaginary)Complex(long real)Complex(long real, long imaginary)Complex(Real real)Complex(Real real, Real imaginary)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description Complexabs()doubleabsNumeric()static doubleabsNumeric(double real, double imaginary)Complexadd(org.apache.commons.math3.fraction.BigFraction fraction)Complexadd(java.math.BigInteger bg)Complexadd(Complex a)Returns aComplexwhose value is(this + addend).Complexadd(double d)Complexadd(int d)Complexadd(long d)Complexadd(Real d)java.math.BigIntegerbigIntValue()Complexconjugate()Return the conjugate of this complex number.Complexdivide(org.apache.commons.math3.fraction.BigFraction fraction)Complexdivide(java.math.BigInteger bg)Complexdivide(Complex divisor)Returns aComplexwhose value is(this / divisor).Complexdivide(double d)Complexdivide(int i)Complexdivide(long l)Complexdivide(Real d)doubledoubleValue()Returns double value of the real part.booleanequals(java.lang.Object obj)ComplexexpNumeric()floatfloatValue()Returns float value of the real part.Tensorget(int i)Returns element at i-th position.TensorBuildergetBuilder()Creates a builder for this tensor.TensorFactorygetFactory()Returns a factory for this tensor.org.apache.commons.math3.Field<Complex>getField()RealgetImaginary()ComplexgetImaginaryAsComplex()ComplexgetImaginaryPart()IndicesgetIndices()Returns indices of this tensor.ComplexgetNumericValue()RealgetReal()ComplexgetRealAsComplex()ComplexgetRealPart()intintValue()Returns int value of the real part.booleanisImaginary()Returnstrueif this number has only imaginary part.booleanisInfinite()booleanisInteger()booleanisMinusOne()booleanisNaN()booleanisNatural()booleanisNegativeNatural()booleanisNumeric()booleanisOne()booleanisOneOrMinusOne()booleanisPositiveNatural()booleanisReal()Returnstrueif this number is real.booleanisZero()ComplexlogNumeric()Returns natural logarithm of thislonglongValue()Returns long value of the real part.Complexmultiply(org.apache.commons.math3.fraction.BigFraction fraction)Complexmultiply(java.math.BigInteger bg)Complexmultiply(Complex factor)Returns aComplexwhose value isthis * factor.Complexmultiply(double d)Complexmultiply(int n)Complexmultiply(long d)Complexmultiply(Real d)Complexnegate()Complexpow(java.math.BigInteger exponent)Complexpow(double exponent)Complexpow(int exponent)Complexpow(long exponent)ComplexpowNumeric(Complex exponent)Complexreciprocal()intsize()Returns the number of elements in this tensor.Complexsubtract(org.apache.commons.math3.fraction.BigFraction fraction)Complexsubtract(java.math.BigInteger bg)Complexsubtract(Complex a)Complexsubtract(double d)Complexsubtract(int i)Complexsubtract(long l)Complexsubtract(Real d)java.lang.StringtoString(OutputFormat mode)Returns a string representation of a tensor according to the specifiedOutputFormat.
-
-
-
Field Detail
-
ComplexNaN
public static final Complex ComplexNaN
-
REAL_POSITIVE_INFINITY
public static final Complex REAL_POSITIVE_INFINITY
-
REAL_NEGATIVE_INFINITY
public static final Complex REAL_NEGATIVE_INFINITY
-
IMAGINARY_POSITIVE_INFINITY
public static final Complex IMAGINARY_POSITIVE_INFINITY
-
IMAGINARY_NEGATIVE_INFINITY
public static final Complex IMAGINARY_NEGATIVE_INFINITY
-
COMPLEX_NEGATIVE_INFINITY
public static final Complex COMPLEX_NEGATIVE_INFINITY
-
COMPLEX_POSITIVE_INFINITY
public static final Complex COMPLEX_POSITIVE_INFINITY
-
COMPLEX_INFINITY
public static final Complex COMPLEX_INFINITY
-
ZERO
public static final Complex ZERO
-
ONE
public static final Complex ONE
-
ONE_HALF
public static final Complex ONE_HALF
-
TWO
public static final Complex TWO
-
FOUR
public static final Complex FOUR
-
MINUS_ONE
public static final Complex MINUS_ONE
-
MINUS_ONE_HALF
public static final Complex MINUS_ONE_HALF
-
MINUS_TWO
public static final Complex MINUS_TWO
-
IMAGINARY_UNIT
public static final Complex IMAGINARY_UNIT
-
NEGATIVE_IMAGINARY_UNIT
public static final Complex NEGATIVE_IMAGINARY_UNIT
-
-
Constructor Detail
-
Complex
public Complex(Real real)
-
Complex
public Complex(org.apache.commons.math3.complex.Complex complex)
-
Complex
public Complex(int real, int imaginary)
-
Complex
public Complex(int real)
-
Complex
public Complex(double real, double imaginary)
-
Complex
public Complex(int real, double imaginary)
-
Complex
public Complex(double real, int imaginary)
-
Complex
public Complex(double real)
-
Complex
public Complex(long real)
-
Complex
public Complex(long real, long imaginary)
-
Complex
public Complex(java.math.BigInteger real, java.math.BigInteger imaginary)
-
Complex
public Complex(java.math.BigInteger real)
-
-
Method Detail
-
get
public Tensor get(int i)
Description copied from class:TensorReturns element at i-th position.
-
getIndices
public Indices getIndices()
Description copied from class:TensorReturns indices of this tensor.- Specified by:
getIndicesin classTensor- Returns:
- indices of this tensor
-
size
public int size()
Description copied from class:TensorReturns the number of elements in this tensor.
-
toString
public java.lang.String toString(OutputFormat mode)
Description copied from class:TensorReturns a string representation of a tensor according to the specifiedOutputFormat.
-
getBuilder
public TensorBuilder getBuilder()
Description copied from class:TensorCreates a builder for this tensor. SeeTensorBuilderfor more information.- Specified by:
getBuilderin classTensor- Returns:
- builder for this tensor
-
getFactory
public TensorFactory getFactory()
Description copied from class:TensorReturns a factory for this tensor. SeeTensorFactoryfor more information.- Specified by:
getFactoryin classTensor- Returns:
- builder for this tensor
-
getImaginary
public Real getImaginary()
-
getReal
public Real getReal()
-
getImaginaryPart
public Complex getImaginaryPart()
-
getRealPart
public Complex getRealPart()
-
isReal
public boolean isReal()
Returnstrueif this number is real.- Returns:
trueif this number is real
-
isImaginary
public boolean isImaginary()
Returnstrueif this number has only imaginary part.- Returns:
trueif this number has only imaginary part
-
getImaginaryAsComplex
public Complex getImaginaryAsComplex()
-
getRealAsComplex
public Complex getRealAsComplex()
-
isInfinite
public boolean isInfinite()
- Specified by:
isInfinitein interfaceNumber<Complex>
-
isMinusOne
public boolean isMinusOne()
- Specified by:
isMinusOnein interfaceNumber<Complex>
-
isOneOrMinusOne
public boolean isOneOrMinusOne()
-
doubleValue
public double doubleValue()
Returns double value of the real part.- Specified by:
doubleValuein interfaceNumber<Complex>- Returns:
- double value of the real part
-
floatValue
public float floatValue()
Returns float value of the real part.- Specified by:
floatValuein interfaceNumber<Complex>- Returns:
- float value of the real part
-
intValue
public int intValue()
Returns int value of the real part.
-
bigIntValue
public java.math.BigInteger bigIntValue()
- Specified by:
bigIntValuein interfaceNumber<Complex>
-
longValue
public long longValue()
Returns long value of the real part.
-
conjugate
public Complex conjugate()
Return the conjugate of this complex number. The conjugate ofa + biisa - bi.
ComplexNaNis 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 notNaN, the returned value has infinite imaginary part of the opposite sign, e.g. the conjugate of1 + POSITIVE_INFINITY iis1 - NEGATIVE_INFINITY i.- Returns:
- the conjugate of this Complex object.
-
add
public Complex add(Complex a)
Returns aComplexwhose value is(this + addend). Uses the definitional formula(a + bi) + (c + di) = (a+c) + (b+d)i
If eitherthisoraddendhas aNaNvalue in either part,ComplexNaNis returned; otherwiseInfiniteandNaNvalues are returned in the parts of the result according to the rules forDoublearithmetic.- Specified by:
addin interfaceorg.apache.commons.math3.FieldElement<Complex>- Parameters:
a- value to be added to thisComplex.- Returns:
this + addend.- Throws:
org.apache.commons.math3.exception.NullArgumentException- ifaddendisnull.
-
divide
public Complex divide(Complex divisor)
Returns aComplexwhose value is(this / divisor). Implements the definitional formula
but uses prescaling of operands to limit the effects of overflows and underflows in the computation.a + bi ac + bd + (bc - ad)i ----------- = ------------------------- c + di c2 + d2
InfiniteandNaNvalues are handled according to the following rules, applied in the order presented:- If either
thisordivisorhas aNaNvalue in either part,ComplexNaNis returned. - If
divisorequalsZERO,ComplexNaNis returned. - If
thisanddivisorare both infinite,ComplexNaNis returned. - If
thisis finite (i.e., has noInfiniteorNaNparts) anddivisoris infinite (one or both parts infinite),ZEROis returned. - If
thisis infinite anddivisoris finite,NaNvalues are returned in the parts of the result if theDoublerules applied to the definitional formula forceNaNresults.
- Specified by:
dividein interfaceorg.apache.commons.math3.FieldElement<Complex>- Parameters:
divisor- Value by which thisComplexis to be divided.- Returns:
this / divisor.- Throws:
org.apache.commons.math3.exception.NullArgumentException- ifdivisorisnull.
- If either
-
getField
public org.apache.commons.math3.Field<Complex> getField()
- Specified by:
getFieldin interfaceorg.apache.commons.math3.FieldElement<Complex>
-
multiply
public Complex multiply(int n)
- Specified by:
multiplyin interfaceorg.apache.commons.math3.FieldElement<Complex>
-
multiply
public Complex multiply(Complex factor)
Returns aComplexwhose value isthis * factor. Implements preliminary checks forNaNand infinity followed by the definitional formula:
Returns(a + bi)(c + di) = (ac - bd) + (ad + bc)iComplexNaNif eitherthisorfactorhas one or moreNaNparts.
ReturnsCOMPLEX_INFINITYif neitherthisnorfactorhas one or moreNaNparts and if eitherthisorfactorhas 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:
multiplyin interfaceorg.apache.commons.math3.FieldElement<Complex>- Parameters:
factor- value to be multiplied by thisComplex.- Returns:
this * factor.- Throws:
org.apache.commons.math3.exception.NullArgumentException- iffactorisnull.
-
negate
public Complex negate()
- Specified by:
negatein interfaceorg.apache.commons.math3.FieldElement<Complex>
-
reciprocal
public Complex reciprocal()
- Specified by:
reciprocalin interfaceorg.apache.commons.math3.FieldElement<Complex>
-
subtract
public Complex subtract(Complex a)
- Specified by:
subtractin interfaceorg.apache.commons.math3.FieldElement<Complex>
-
getNumericValue
public Complex getNumericValue()
- Specified by:
getNumericValuein interfaceNumber<Complex>
-
absNumeric
public double absNumeric()
-
absNumeric
public static double absNumeric(double real, double imaginary)
-
add
public Complex add(org.apache.commons.math3.fraction.BigFraction fraction)
-
subtract
public Complex subtract(org.apache.commons.math3.fraction.BigFraction fraction)
-
subtract
public Complex subtract(java.math.BigInteger bg)
-
multiply
public Complex multiply(org.apache.commons.math3.fraction.BigFraction fraction)
-
multiply
public Complex multiply(java.math.BigInteger bg)
-
divide
public Complex divide(org.apache.commons.math3.fraction.BigFraction fraction)
-
divide
public Complex divide(java.math.BigInteger bg)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
logNumeric
public Complex logNumeric()
Returns natural logarithm of this- Returns:
- natural logarithm of this
-
pow
public Complex pow(java.math.BigInteger exponent)
-
expNumeric
public Complex expNumeric()
-
isNegativeNatural
public boolean isNegativeNatural()
-
isPositiveNatural
public boolean isPositiveNatural()
-
-
DataMelt 3.0 © DataMelt by jWork.ORG