- java.lang.Object
-
- org.ojalgo.scalar.BigScalar
-
- All Implemented Interfaces:
java.lang.Comparable<java.math.BigDecimal>,Field<Scalar<java.math.BigDecimal>>,Group,Group.Additive<Scalar<java.math.BigDecimal>>,Group.Multiplicative<Scalar<java.math.BigDecimal>>,NormedVectorSpace<Scalar<java.math.BigDecimal>,java.math.BigDecimal>,Operation,Operation.Addition<Scalar<java.math.BigDecimal>>,Operation.Division<Scalar<java.math.BigDecimal>>,Operation.Multiplication<Scalar<java.math.BigDecimal>>,Operation.Subtraction<Scalar<java.math.BigDecimal>>,Ring<Scalar<java.math.BigDecimal>>,ScalarOperation,ScalarOperation.Addition<Scalar<java.math.BigDecimal>,java.math.BigDecimal>,ScalarOperation.Division<Scalar<java.math.BigDecimal>,java.math.BigDecimal>,ScalarOperation.Multiplication<Scalar<java.math.BigDecimal>,java.math.BigDecimal>,ScalarOperation.Subtraction<Scalar<java.math.BigDecimal>,java.math.BigDecimal>,VectorSpace<Scalar<java.math.BigDecimal>,java.math.BigDecimal>,Scalar<java.math.BigDecimal>,AccessScalar<java.math.BigDecimal>,Tensor<java.math.BigDecimal,Scalar<java.math.BigDecimal>>,NumberContext.Enforceable<BigScalar>,NumberDefinition
public final class BigScalar extends java.lang.Object implements Scalar<java.math.BigDecimal>, NumberContext.Enforceable<BigScalar>
ABigDecimalbased implementation of theScalarinterface. Most/all other implementations are based on primitive components. This implementation exists for historical reasons, and is now primarily used for tests.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.ojalgo.algebra.Group
Group.Additive<T>, Group.Multiplicative<T>
-
Nested classes/interfaces inherited from interface org.ojalgo.algebra.Operation
Operation.Addition<T>, Operation.Division<T>, Operation.Multiplication<T>, Operation.Subtraction<T>
-
Nested classes/interfaces inherited from interface org.ojalgo.scalar.Scalar
Scalar.Factory<N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface org.ojalgo.algebra.ScalarOperation
ScalarOperation.Addition<T,N extends java.lang.Comparable<N>>, ScalarOperation.Division<T,N extends java.lang.Comparable<N>>, ScalarOperation.Multiplication<T,N extends java.lang.Comparable<N>>, ScalarOperation.Subtraction<T,N extends java.lang.Comparable<N>>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BigScalaradd(double arg)BigScalaradd(float scalarAddend)BigScalaradd(java.math.BigDecimal arg)intcompareTo(java.math.BigDecimal reference)BigScalarconjugate()This method will (most likely) be moved to some other interface in the future! Just have to figure out where it fits...BigScalardivide(double arg)BigScalardivide(float scalarDivisor)BigScalardivide(java.math.BigDecimal arg)doubledoubleValue()BigScalarenforce(NumberContext context)booleanequals(java.lang.Object obj)floatfloatValue()java.math.BigDecimalget()inthashCode()intintValue()BigScalarinvert()The multiplicative inverse.booleanisAbsolute()static booleanisAbsolute(java.math.BigDecimal value)booleanisSmall(double comparedTo)static booleanisSmall(double comparedTo, java.math.BigDecimal value)booleanisZero()Tests if this scalar value is exactly zero.longlongValue()BigScalarmultiply(double arg)BigScalarmultiply(float scalarMultiplicand)BigScalarmultiply(java.math.BigDecimal arg)BigScalarnegate()The additive inverse of this.doublenorm()this == this.signum().multiply(this.norm())static BigScalarof(java.math.BigDecimal value)BigScalarpower(int power)Multiply by itselfpowertimes.BigScalarsignum()this == this.signum().multiply(this.norm())BigScalarsubtract(double arg)BigScalarsubtract(float scalarSubtrahend)BigScalarsubtract(java.math.BigDecimal arg)java.math.BigDecimaltoBigDecimal()java.lang.StringtoString()java.lang.StringtoString(NumberContext context)static BigScalarvalueOf(double value)static BigScalarvalueOf(java.lang.Comparable<?> number)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.ojalgo.type.NumberDefinition
booleanValue, byteValue, shortValue
-
Methods inherited from interface org.ojalgo.scalar.Scalar
add, dimensions, divide, multiply, rank, subtract, toPlainString
-
Methods inherited from interface org.ojalgo.tensor.Tensor
components, isSameShape
-
-
-
-
Field Detail
-
FACTORY
public static final Scalar.Factory<java.math.BigDecimal> FACTORY
-
NEG
public static final BigScalar NEG
-
ONE
public static final BigScalar ONE
-
TWO
public static final BigScalar TWO
-
ZERO
public static final BigScalar ZERO
-
CONTEXT
static final NumberContext CONTEXT
-
myNumber
private final java.math.BigDecimal myNumber
-
-
Method Detail
-
isAbsolute
public static boolean isAbsolute(java.math.BigDecimal value)
-
isSmall
public static boolean isSmall(double comparedTo, java.math.BigDecimal value)
-
of
public static BigScalar of(java.math.BigDecimal value)
-
valueOf
public static BigScalar valueOf(java.lang.Comparable<?> number)
-
valueOf
public static BigScalar valueOf(double value)
-
add
public BigScalar add(java.math.BigDecimal arg)
- Specified by:
addin interfaceScalarOperation.Addition<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
this + scalarAddend.
-
add
public BigScalar add(double arg)
- Specified by:
addin interfaceScalarOperation.Addition<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
this + scalarAddend.
-
add
public BigScalar add(float scalarAddend)
- Specified by:
addin interfaceScalarOperation.Addition<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
this + scalarAddend.
-
compareTo
public int compareTo(java.math.BigDecimal reference)
- Specified by:
compareToin interfacejava.lang.Comparable<java.math.BigDecimal>
-
conjugate
public BigScalar conjugate()
Description copied from interface:VectorSpaceThis method will (most likely) be moved to some other interface in the future! Just have to figure out where it fits...
The conjugate transpose of a matrix and/or the conjugate of a scalar/field like ComplexNumber or Quaternion.
The conjugate transpose of a real matrix is simply its transpose.
- Specified by:
conjugatein interfaceVectorSpace<Scalar<java.math.BigDecimal>,java.math.BigDecimal>
-
divide
public BigScalar divide(java.math.BigDecimal arg)
- Specified by:
dividein interfaceScalarOperation.Division<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
this / scalarDivisor.
-
divide
public BigScalar divide(double arg)
- Specified by:
dividein interfaceScalarOperation.Division<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
this / scalarDivisor.
-
divide
public BigScalar divide(float scalarDivisor)
- Specified by:
dividein interfaceScalarOperation.Division<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
this / scalarDivisor.
-
doubleValue
public double doubleValue()
- Specified by:
doubleValuein interfaceNumberDefinition
-
enforce
public BigScalar enforce(NumberContext context)
- Specified by:
enforcein interfaceNumberContext.Enforceable<BigScalar>
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
floatValue
public float floatValue()
- Specified by:
floatValuein interfaceNumberDefinition
-
get
public java.math.BigDecimal get()
- Specified by:
getin interfaceAccessScalar<java.math.BigDecimal>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
intValue
public int intValue()
- Specified by:
intValuein interfaceNumberDefinition
-
invert
public BigScalar invert()
Description copied from interface:Group.MultiplicativeThe multiplicative inverse.- Specified by:
invertin interfaceGroup.Multiplicative<Scalar<java.math.BigDecimal>>- Returns:
IDENTITY / this.
-
isAbsolute
public boolean isAbsolute()
- Specified by:
isAbsolutein interfaceScalar<java.math.BigDecimal>- Returns:
- true if this is equal to its own norm, modulus or absolute value (non-negative real part and no imaginary part); otherwise false.
- See Also:
Scalar.isAbsolute()
-
isSmall
public boolean isSmall(double comparedTo)
- Specified by:
isSmallin interfaceNormedVectorSpace<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Parameters:
comparedTo- What to compare with- Returns:
- true if this is small compared to the magnitude of the input reference value.
-
isZero
public boolean isZero()
Description copied from interface:ScalarTests if this scalar value is exactly zero.Each implementation should test for zero as exactly as possible based on what's achievable with that specific scalar type. The purpose is NOT to have similar behavior between different implementations, but rather to leverage the full precision and capabilities of each type.
For example:
- Primitive types (like
double) should use exact equality comparison - High-precision types (like
Quadruple) should check both base and remainder components - Arbitrary-precision types (like
BigDecimal) should use their built-in zero detection - Complex types should check both real and imaginary parts
This method should NOT use tolerance-based comparisons or approximate zero detection, as those are better handled by context-aware methods like
NormedVectorSpace.isSmall(double).- Specified by:
isZeroin interfaceScalar<java.math.BigDecimal>- Returns:
- true if this scalar represents exactly zero, false otherwise
- See Also:
NormedVectorSpace.isSmall(double)
- Primitive types (like
-
longValue
public long longValue()
- Specified by:
longValuein interfaceNumberDefinition
-
multiply
public BigScalar multiply(java.math.BigDecimal arg)
- Specified by:
multiplyin interfaceScalarOperation.Multiplication<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
this * multiplicand.
-
multiply
public BigScalar multiply(double arg)
- Specified by:
multiplyin interfaceScalarOperation.Multiplication<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
this * scalarMultiplicand.
-
multiply
public BigScalar multiply(float scalarMultiplicand)
- Specified by:
multiplyin interfaceScalarOperation.Multiplication<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
this * scalarMultiplicand.
-
negate
public BigScalar negate()
Description copied from interface:Group.AdditiveThe additive inverse of this.- Specified by:
negatein interfaceGroup.Additive<Scalar<java.math.BigDecimal>>- Returns:
-this.
-
norm
public double norm()
Description copied from interface:NormedVectorSpacethis == this.signum().multiply(this.norm())- Specified by:
normin interfaceNormedVectorSpace<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
- The norm
-
power
public BigScalar power(int power)
Description copied from interface:Operation.MultiplicationMultiply by itselfpowertimes.- Specified by:
powerin interfaceOperation.Multiplication<Scalar<java.math.BigDecimal>>
-
signum
public BigScalar signum()
Description copied from interface:NormedVectorSpacethis == this.signum().multiply(this.norm())- Specified by:
signumin interfaceNormedVectorSpace<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
- A unit "vector"
-
subtract
public BigScalar subtract(java.math.BigDecimal arg)
- Specified by:
subtractin interfaceScalarOperation.Subtraction<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
this - scalarSubtrahend.
-
subtract
public BigScalar subtract(double arg)
- Specified by:
subtractin interfaceScalarOperation.Subtraction<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
this - scalarSubtrahend.
-
subtract
public BigScalar subtract(float scalarSubtrahend)
- Specified by:
subtractin interfaceScalarOperation.Subtraction<Scalar<java.math.BigDecimal>,java.math.BigDecimal>- Returns:
this - scalarSubtrahend.
-
toBigDecimal
public java.math.BigDecimal toBigDecimal()
- Specified by:
toBigDecimalin interfaceScalar<java.math.BigDecimal>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString
public java.lang.String toString(NumberContext context)
-
-