Class IntJumpDistances

java.lang.Object
org.apache.commons.rng.core.source32.IntJumpDistances

final class IntJumpDistances extends Object
Utility for working with positive integer jump distances represented as 32-bit integers.
Since:
1.7
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final long
    Mask to extract the 52-bit mantissa from a long representation of a double.
    private static final int
    The value of the exponent for NaN when the exponent is extracted and scaled to account for multiplying the floating-point 52-bit mantissa to an integer.
    private static final double
    2^63.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Class contains only static methods.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static void
    validateJump(double distance, double period)
    Validate the jump distance is valid within the given period of the cycle.
    (package private) static void
    validateJumpPowerOfTwo(int logDistance, int logPeriod)
    Validate the jump distance of 2logDistance is valid within the given cycle period of 2logPeriod.
    (package private) static void
    writeUnsignedInteger(double value, int[] result)
    Write the value to an unsigned integer representation.

    Methods inherited from class Object

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

    • TWO_POW_63

      private static final double TWO_POW_63
      2^63.
      See Also:
    • NAN_EXP

      private static final int NAN_EXP
      The value of the exponent for NaN when the exponent is extracted and scaled to account for multiplying the floating-point 52-bit mantissa to an integer. 1024 - 52 = 972.
      See Also:
    • MANTISSA_MASK

      private static final long MANTISSA_MASK
      Mask to extract the 52-bit mantissa from a long representation of a double.
      See Also:
  • Constructor Details

    • IntJumpDistances

      private IntJumpDistances()
      Class contains only static methods.
  • Method Details

    • validateJump

      static void validateJump(double distance, double period)
      Validate the jump distance is valid within the given period of the cycle.
      Parameters:
      distance - Jump distance.
      period - Cycle period.
      Throws:
      IllegalArgumentException - if distance is negative, or is greater than the period.
    • validateJumpPowerOfTwo

      static void validateJumpPowerOfTwo(int logDistance, int logPeriod)
      Validate the jump distance of 2logDistance is valid within the given cycle period of 2logPeriod.

      Note: Negative logDistance is allowed as the distance is >= 0.

      Parameters:
      logDistance - Base-2 logarithm of the distance to jump forward with the state cycle.
      logPeriod - Base-2 logarithm of the cycle period.
      Throws:
      IllegalArgumentException - if logDistance >= logPeriod.
    • writeUnsignedInteger

      static void writeUnsignedInteger(double value, int[] result)
      Write the value to an unsigned integer representation. Any fractional part of the floating-point value is discarded. The integer part of the value must be positive or an exception is raised.

      The 53-bit significand of the value is converted to an integer, shifted to align with a 32-bit boundary and written to the provided result, ordered with the least significant bits first.

      No bounds checking is performed. The result array is assumed to have a length of at least 2 to store an unshifted 53-bit significand. The required array size for values larger than 2^53 can be computed using:

      1 + Math.getExponent(value) / 32
      

      Parts of the array not used by the significand are unchanged. It is recommended to use a newly created array for the result.

      Note: For jump distances validated as less than the period of an output cycle the result array length can be preallocated based on the maximum possible length.

      Parameters:
      value - Value
      result - the integer representation
      Throws:
      IllegalArgumentException - if the value is negative or non-finite.