Class NumberFactory
java.lang.Object
org.apache.commons.rng.core.util.NumberFactory
Utility for creating number types from one or two
int values
or one long value, or a sequence of bytes.-
Method Summary
Modifier and TypeMethodDescriptionstatic intextractHi(long v) Creates anintfrom along, using the high order bits.static intextractLo(long v) Creates anintfrom along, using the low order bits.static booleanmakeBoolean(int v) Deprecated.Since version 1.2.static booleanmakeBoolean(long v) Deprecated.Since version 1.2.static byte[]makeByteArray(int v) Splits anintinto 4 bytes.static byte[]makeByteArray(int[] input) Splits an array ofintvalues into a sequence of bytes.static byte[]makeByteArray(long v) Splits alonginto 8 bytes.static byte[]makeByteArray(long[] input) Splits an array oflongvalues into a sequence of bytes.static doublemakeDouble(int v, int w) Creates adoublefrom twointvalues.static doublemakeDouble(long v) Creates adoublefrom alongvalue.static floatmakeFloat(int v) Creates afloatfrom anintvalue.static intmakeInt(byte[] input) Creates anintfrom 4 bytes.static intmakeInt(long v) Deprecated.Since version 1.2.static int[]makeIntArray(byte[] input) Creates an array ofintvalues from a sequence of bytes.static longmakeLong(byte[] input) Creates alongfrom 8 bytes.static longmakeLong(int v, int w) Creates alongfrom twointvalues.static long[]makeLongArray(byte[] input) Creates an array oflongvalues from a sequence of bytes.
-
Method Details
-
makeBoolean
Deprecated.Since version 1.2. Method has become obsolete following RNG-57.Creates abooleanfrom anintvalue.- Parameters:
v- Number.- Returns:
- a boolean.
-
makeBoolean
Deprecated.Since version 1.2. Method has become obsolete following RNG-57.Creates abooleanfrom alongvalue.- Parameters:
v- Number.- Returns:
- a boolean.
-
makeDouble
Creates adoublefrom alongvalue.- Parameters:
v- Number.- Returns:
- a
doublevalue in the interval[0, 1].
-
makeDouble
Creates adoublefrom twointvalues.- Parameters:
v- Number (high order bits).w- Number (low order bits).- Returns:
- a
doublevalue in the interval[0, 1].
-
makeFloat
Creates afloatfrom anintvalue.- Parameters:
v- Number.- Returns:
- a
floatvalue in the interval[0, 1].
-
makeLong
Creates alongfrom twointvalues.- Parameters:
v- Number (high order bits).w- Number (low order bits).- Returns:
- a
longvalue.
-
makeInt
Deprecated.Since version 1.2. Method has become obsolete following RNG-57.Creates anintfrom along.- Parameters:
v- Number.- Returns:
- an
intvalue made from the "xor" of thehigh order bitsandlow order bitsofv.
-
extractHi
Creates anintfrom along, using the high order bits.The returned value is such that if
vL = extractLo(v); vH = extractHi(v);then
vis equal tomakeLong(vH, vL).- Parameters:
v- Number.- Returns:
- an
intvalue made from the most significant bits ofv.
-
extractLo
Creates anintfrom along, using the low order bits.The returned value is such that if
vL = extractLo(v); vH = extractHi(v);then
vis equal tomakeLong(vH, vL).- Parameters:
v- Number.- Returns:
- an
intvalue made from the least significant bits ofv.
-
makeByteArray
Splits alonginto 8 bytes.- Parameters:
v- Value.- Returns:
- the bytes that compose the given value (least-significant byte first).
-
makeLong
Creates alongfrom 8 bytes.- Parameters:
input- Input.- Returns:
- the value that correspond to the given bytes assuming that the order is in increasing byte significance (i.e. the first byte in the array is the least-significant).
- Throws:
IllegalArgumentException- ifinput.length != 8.
-
makeByteArray
Splits an array oflongvalues into a sequence of bytes. This method callsmakeByteArray(long)for each element of theinput.- Parameters:
input- Input.- Returns:
- an array of bytes.
-
makeLongArray
Creates an array oflongvalues from a sequence of bytes. This method callsmakeLong(byte[])for each subsequence of 8 bytes.- Parameters:
input- Input.- Returns:
- an array of
long. - Throws:
IllegalArgumentException- ifinput.lengthis not a multiple of 8.
-
makeByteArray
Splits anintinto 4 bytes.- Parameters:
v- Value.- Returns:
- the bytes that compose the given value (least-significant byte first).
-
makeInt
Creates anintfrom 4 bytes.- Parameters:
input- Input.- Returns:
- the value that correspond to the given bytes assuming that the order is in increasing byte significance (i.e. the first byte in the array is the least-significant).
- Throws:
IllegalArgumentException- ifinput.length != 4.
-
makeByteArray
Splits an array ofintvalues into a sequence of bytes. This method callsmakeByteArray(int)for each element of theinput.- Parameters:
input- Input.- Returns:
- an array of bytes.
-
makeIntArray
Creates an array ofintvalues from a sequence of bytes. This method callsmakeInt(byte[])for each subsequence of 4 bytes.- Parameters:
input- Input. Length must be a multiple of 4.- Returns:
- an array of
int. - Throws:
IllegalArgumentException- ifinput.lengthis not a multiple of 4.
-