Interface Scalar<N extends Comparable<N>>

All Superinterfaces:
AccessScalar<N>, 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 Comparable<N>> extends AccessScalar<N>, Field<Scalar<N>>, ScalarOperation.Addition<Scalar<N>, N>, ScalarOperation.Division<Scalar<N>, N>, ScalarOperation.Subtraction<Scalar<N>, N>, Comparable<N>, Tensor<N, Scalar<N>>

A Scalar is:

  1. An abstraction of a vector/matrix element.
  2. 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 Comparable and that they should be inline with the requirements for ValueBased classes.

  • Method Details

    • booleanValue

      static boolean booleanValue(Comparable<?> number)
    • byteValue

      static byte byteValue(Comparable<?> number)
    • doubleValue

      static double doubleValue(Comparable<?> number)
    • floatValue

      static float floatValue(Comparable<?> number)
    • intValue

      static int intValue(Comparable<?> number)
    • longValue

      static long longValue(Comparable<?> number)
    • shortValue

      static short shortValue(Comparable<?> number)
    • add

      default Scalar<N> add(Scalar<N> addend)
      Specified by:
      add in interface Operation.Addition<N extends Comparable<N>>
      Parameters:
      addend - What to add
      Returns:
      this + addend
    • dimensions

      default int dimensions()
      Description copied from interface: Tensor
      The range of the indices that identify the scalar components. Each index of a tensor ranges over the number of dimensions.
      Specified by:
      dimensions in interface Tensor<N extends Comparable<N>, Scalar<N extends Comparable<N>>>
    • divide

      default Scalar<N> divide(Scalar<N> divisor)
      Specified by:
      divide in interface Operation.Division<N extends 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:
    • 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:
    • multiply

      default Scalar<N> multiply(Scalar<N> multiplicand)
      Specified by:
      multiply in interface Operation.Multiplication<N extends Comparable<N>>
      Parameters:
      multiplicand - The multiplicand
      Returns:
      this * multiplicand.
    • rank

      default int rank()
      Description copied from interface: Tensor
      The total number of indices required to uniquely identify each scalar component is called the order, degree or rank of the tensor.
      Specified by:
      rank in interface Tensor<N extends Comparable<N>, Scalar<N extends Comparable<N>>>
    • subtract

      default Scalar<N> subtract(Scalar<N> subtrahend)
      Specified by:
      subtract in interface Operation.Subtraction<N extends Comparable<N>>
      Parameters:
      subtrahend - The subtrahend
      Returns:
      this - subtrahend.
    • toBigDecimal

      BigDecimal toBigDecimal()
    • toPlainString

      default String toPlainString(NumberContext context)
    • toString

      String toString(NumberContext context)