Class LongJumpDistances
java.lang.Object
org.apache.commons.rng.core.source64.LongJumpDistances
Utility for working with positive integer jump distances represented
as 64-bit integers.
- Since:
- 1.7
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final longMask to extract the 52-bit mantissa from a long representation of a double.private static final intThe 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 intSmall shift of a 53-bit significand where it remains within the same long.private static final double2^63. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static voidvalidateJump(double distance, double period) Validate the jumpdistanceis valid within the givenperiodof the cycle.(package private) static voidvalidateJumpPowerOfTwo(int logDistance, int logPeriod) Validate the jump distance of 2logDistanceis valid within the given cycle period of 2logPeriod.(package private) static voidwriteUnsignedInteger(double value, long[] result) Write thevalueto an unsigned integer representation.
-
Field Details
-
TWO_POW_63
private static final double TWO_POW_632^63.- See Also:
-
NAN_EXP
private static final int NAN_EXPThe 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_MASKMask to extract the 52-bit mantissa from a long representation of a double.- See Also:
-
SMALL_SHIFT
private static final int SMALL_SHIFTSmall shift of a 53-bit significand where it remains within the same long.- See Also:
-
-
Constructor Details
-
LongJumpDistances
private LongJumpDistances()Class contains only static methods.
-
-
Method Details
-
validateJump
static void validateJump(double distance, double period) Validate the jumpdistanceis valid within the givenperiodof the cycle.- Parameters:
distance- Jump distance.period- Cycle period.- Throws:
IllegalArgumentException- ifdistanceis negative, or is greater than theperiod.
-
validateJumpPowerOfTwo
static void validateJumpPowerOfTwo(int logDistance, int logPeriod) Validate the jump distance of 2logDistanceis valid within the given cycle period of 2logPeriod.Note: Negative
logDistanceis 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- iflogDistance >= logPeriod.
-
writeUnsignedInteger
static void writeUnsignedInteger(double value, long[] result) Write thevalueto 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
valueis converted to an integer, shifted to align with a 64-bit boundary and written to the providedresult, ordered with the least significant bits first.No bounds checking is performed. The
resultarray is assumed to have a length of at least 1 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) / 64
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- Valueresult- the integer representation- Throws:
IllegalArgumentException- if thevalueis negative or non-finite.
-