java.lang.Object
org.apache.commons.statistics.descriptive.Int128

final class Int128 extends Object
A mutable 128-bit signed integer.

This is a specialised class to implement an accumulator of long values.

Note: This number uses a signed long integer representation of:

value = 264 * hi64 + lo64

If the high value is zero then the low value is the long representation of the number including the sign bit. Otherwise the low value corresponds to a correction term for the scaled high value which contains the sign-bit of the number.

Since:
1.1
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private long
    high 64-bits.
    private long
    low 64-bits.
    private static final long
    Mask for the lower 32-bits of a long.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Create an instance.
    private
    Int128(long x)
    Create an instance.
    (package private)
    Int128(long hi, long lo)
    Create an instance using a direct binary representation.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    add(long x)
    Adds the value.
    (package private) void
    Adds the value.
    (package private) static Int128
    Create an instance.
    (package private) long
    Return the higher 64-bits as a long value.
    (package private) long
    Return the lower 64-bits as a long value.
    (package private) static Int128
    of(long x)
    Create an instance of the long value.
    (package private) UInt128
    Compute the square of the low 64-bits of this number.
    (package private) BigInteger
    Convert to a BigInteger.
    (package private) org.apache.commons.numbers.core.DD
    Convert to a double-double.
    (package private) double
    Convert to a double.
    (package private) int
    Convert to an int; throwing an exception if the value overflows an int.
    (package private) long
    Convert to a long; throwing an exception if the value overflows a long.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MASK32

      private static final long MASK32
      Mask for the lower 32-bits of a long.
      See Also:
    • lo

      private long lo
      low 64-bits.
    • hi

      private long hi
      high 64-bits.
  • Constructor Details

    • Int128

      private Int128()
      Create an instance.
    • Int128

      private Int128(long x)
      Create an instance.
      Parameters:
      x - Value.
    • Int128

      Int128(long hi, long lo)
      Create an instance using a direct binary representation. This is package-private for testing.
      Parameters:
      hi - High 64-bits.
      lo - Low 64-bits.
  • Method Details

    • create

      static Int128 create()
      Create an instance. The initial value is zero.
      Returns:
      the instance
    • of

      static Int128 of(long x)
      Create an instance of the long value.
      Parameters:
      x - Value.
      Returns:
      the instance
    • add

      void add(long x)
      Adds the value.
      Parameters:
      x - Value.
    • add

      void add(Int128 x)
      Adds the value.
      Parameters:
      x - Value.
    • squareLow

      UInt128 squareLow()
      Compute the square of the low 64-bits of this number.

      Warning: This ignores the upper 64-bits. Use with caution.

      Returns:
      the square
    • toBigInteger

      BigInteger toBigInteger()
      Convert to a BigInteger.
      Returns:
      the value
    • toDouble

      double toDouble()
      Convert to a double.
      Returns:
      the value
    • toDD

      org.apache.commons.numbers.core.DD toDD()
      Convert to a double-double.
      Returns:
      the value
    • toIntExact

      int toIntExact()
      Convert to an int; throwing an exception if the value overflows an int.
      Returns:
      the value
      Throws:
      ArithmeticException - if the value overflows an int.
      See Also:
    • toLongExact

      long toLongExact()
      Convert to a long; throwing an exception if the value overflows a long.
      Returns:
      the value
      Throws:
      ArithmeticException - if the value overflows a long.
    • lo64

      long lo64()
      Return the lower 64-bits as a long value.

      If the high value is zero then the low value is the long representation of the number including the sign bit. Otherwise this value corresponds to a correction term for the scaled high value which contains the sign-bit of the number (see Int128).

      Returns:
      the low 64-bits
    • hi64

      long hi64()
      Return the higher 64-bits as a long value.
      Returns:
      the high 64-bits
      See Also: