-
- All Superinterfaces:
AccessScalar<N>,java.lang.Comparable<N>,Field<Scalar<N>>,Group,Group.Additive<Scalar<N>>,Group.Multiplicative<Scalar<N>>,NormedVectorSpace<Scalar<N>,N>,NumberDefinition,Operation,Operation.Addition<Scalar<N>>,Operation.Division<Scalar<N>>,Operation.Multiplication<Scalar<N>>,Operation.Subtraction<Scalar<N>>,Ring<Scalar<N>>,ScalarOperation,ScalarOperation.Addition<Scalar<N>,N>,ScalarOperation.Division<Scalar<N>,N>,ScalarOperation.Multiplication<Scalar<N>,N>,ScalarOperation.Subtraction<Scalar<N>,N>,Tensor<N,Scalar<N>>,VectorSpace<Scalar<N>,N>
- All Known Subinterfaces:
SelfDeclaringScalar<S>
- All Known Implementing Classes:
Amount,BigScalar,ComplexNumber,ExactDecimal,Money,Price,PrimitiveScalar,Quadruple,Quantity,Quaternion,RationalNumber
public interface Scalar<N extends java.lang.Comparable<N>> extends AccessScalar<N>, Field<Scalar<N>>, ScalarOperation.Addition<Scalar<N>,N>, ScalarOperation.Division<Scalar<N>,N>, ScalarOperation.Subtraction<Scalar<N>,N>, java.lang.Comparable<N>, Tensor<N,Scalar<N>>
A Scalar is:
- An abstraction of a vector/matrix element.
- A Comparable decorator, increasing the number of things you can do with them.
Theoretically it is a Field or at least a Division ring.
The intention is that implementors should be final immutable subclasses of
Comparableand that they should be inline with the requirements for ValueBased classes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceScalar.Factory<N extends java.lang.Comparable<N>>-
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.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 Abstract Methods Default Methods Modifier and Type Method Description default Scalar<N>add(Scalar<N> addend)static booleanbooleanValue(java.lang.Comparable<?> number)static bytebyteValue(java.lang.Comparable<?> number)default intdimensions()The range of the indices that identify the scalar components.default Scalar<N>divide(Scalar<N> divisor)static doubledoubleValue(java.lang.Comparable<?> number)static floatfloatValue(java.lang.Comparable<?> number)static intintValue(java.lang.Comparable<?> number)booleanisAbsolute()booleanisZero()Tests if this scalar value is exactly zero.static longlongValue(java.lang.Comparable<?> number)default Scalar<N>multiply(Scalar<N> multiplicand)default intrank()The total number of indices required to uniquely identify each scalar component is called the order, degree or rank of the tensor.static shortshortValue(java.lang.Comparable<?> number)default Scalar<N>subtract(Scalar<N> subtrahend)java.math.BigDecimaltoBigDecimal()default java.lang.StringtoPlainString(NumberContext context)java.lang.StringtoString(NumberContext context)-
Methods inherited from interface org.ojalgo.structure.AccessScalar
get
-
Methods inherited from interface org.ojalgo.algebra.Group.Additive
negate
-
Methods inherited from interface org.ojalgo.algebra.Group.Multiplicative
invert
-
Methods inherited from interface org.ojalgo.algebra.NormedVectorSpace
isSmall, norm, signum
-
Methods inherited from interface org.ojalgo.type.NumberDefinition
booleanValue, byteValue, doubleValue, floatValue, intValue, longValue, shortValue
-
Methods inherited from interface org.ojalgo.algebra.Operation.Multiplication
power
-
Methods inherited from interface org.ojalgo.algebra.ScalarOperation.Addition
add, add, add
-
Methods inherited from interface org.ojalgo.algebra.ScalarOperation.Division
divide, divide, divide
-
Methods inherited from interface org.ojalgo.algebra.ScalarOperation.Multiplication
multiply, multiply, multiply
-
Methods inherited from interface org.ojalgo.algebra.ScalarOperation.Subtraction
subtract, subtract, subtract
-
Methods inherited from interface org.ojalgo.tensor.Tensor
components, isSameShape
-
Methods inherited from interface org.ojalgo.algebra.VectorSpace
conjugate
-
-
-
-
Method Detail
-
booleanValue
static boolean booleanValue(java.lang.Comparable<?> number)
-
byteValue
static byte byteValue(java.lang.Comparable<?> number)
-
doubleValue
static double doubleValue(java.lang.Comparable<?> number)
-
floatValue
static float floatValue(java.lang.Comparable<?> number)
-
intValue
static int intValue(java.lang.Comparable<?> number)
-
longValue
static long longValue(java.lang.Comparable<?> number)
-
shortValue
static short shortValue(java.lang.Comparable<?> number)
-
add
default Scalar<N> add(Scalar<N> addend)
- Specified by:
addin interfaceOperation.Addition<N extends java.lang.Comparable<N>>- Parameters:
addend- What to add- Returns:
this + addend
-
dimensions
default int dimensions()
Description copied from interface:TensorThe range of the indices that identify the scalar components. Each index of a tensor ranges over the number of dimensions.
-
divide
default Scalar<N> divide(Scalar<N> divisor)
- Specified by:
dividein interfaceOperation.Division<N extends java.lang.Comparable<N>>- Parameters:
divisor- The divisor- Returns:
this / divisor.
-
isAbsolute
boolean isAbsolute()
- 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:
isAbsolute()
-
isZero
boolean isZero()
Tests 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).- Returns:
- true if this scalar represents exactly zero, false otherwise
- See Also:
NormedVectorSpace.isSmall(double)
- Primitive types (like
-
multiply
default Scalar<N> multiply(Scalar<N> multiplicand)
- Specified by:
multiplyin interfaceOperation.Multiplication<N extends java.lang.Comparable<N>>- Parameters:
multiplicand- The multiplicand- Returns:
this * multiplicand.
-
rank
default int rank()
Description copied from interface:TensorThe total number of indices required to uniquely identify each scalar component is called the order, degree or rank of the tensor.
-
subtract
default Scalar<N> subtract(Scalar<N> subtrahend)
- Specified by:
subtractin interfaceOperation.Subtraction<N extends java.lang.Comparable<N>>- Parameters:
subtrahend- The subtrahend- Returns:
this - subtrahend.
-
toBigDecimal
java.math.BigDecimal toBigDecimal()
-
toPlainString
default java.lang.String toPlainString(NumberContext context)
-
toString
java.lang.String toString(NumberContext context)
-
-