Package org.apache.commons.rng.core.util
Class NumberFactory
- java.lang.Object
-
- org.apache.commons.rng.core.util.NumberFactory
-
public final class NumberFactory extends Object
Utility for creating number types from one or twoint
values or onelong
value, or a sequence of bytes.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static int
extractHi(long v)
Creates anint
from along
, using the high order bits.static int
extractLo(long v)
Creates anint
from along
, using the low order bits.static boolean
makeBoolean(int v)
Deprecated.Since version 1.2.static boolean
makeBoolean(long v)
Deprecated.Since version 1.2.static byte[]
makeByteArray(int v)
Splits anint
into 4 bytes.static byte[]
makeByteArray(int[] input)
Splits an array ofint
values into a sequence of bytes.static byte[]
makeByteArray(long v)
Splits along
into 8 bytes.static byte[]
makeByteArray(long[] input)
Splits an array oflong
values into a sequence of bytes.static double
makeDouble(int v, int w)
Creates adouble
from twoint
values.static double
makeDouble(long v)
Creates adouble
from along
value.static float
makeFloat(int v)
Creates afloat
from anint
value.static int
makeInt(byte[] input)
Creates anint
from 4 bytes.static int
makeInt(long v)
Deprecated.Since version 1.2.static int[]
makeIntArray(byte[] input)
Creates an array ofint
values from a sequence of bytes.static long
makeLong(byte[] input)
Creates along
from 8 bytes.static long
makeLong(int v, int w)
Creates along
from twoint
values.static long[]
makeLongArray(byte[] input)
Creates an array oflong
values from a sequence of bytes.
-
-
-
Method Detail
-
makeBoolean
@Deprecated public static boolean makeBoolean(int v)
Deprecated.Since version 1.2. Method has become obsolete following RNG-57.Creates aboolean
from anint
value.- Parameters:
v
- Number.- Returns:
- a boolean.
-
makeBoolean
@Deprecated public static boolean makeBoolean(long v)
Deprecated.Since version 1.2. Method has become obsolete following RNG-57.Creates aboolean
from along
value.- Parameters:
v
- Number.- Returns:
- a boolean.
-
makeDouble
public static double makeDouble(long v)
Creates adouble
from along
value.- Parameters:
v
- Number.- Returns:
- a
double
value in the interval[0, 1]
.
-
makeDouble
public static double makeDouble(int v, int w)
Creates adouble
from twoint
values.- Parameters:
v
- Number (high order bits).w
- Number (low order bits).- Returns:
- a
double
value in the interval[0, 1]
.
-
makeFloat
public static float makeFloat(int v)
Creates afloat
from anint
value.- Parameters:
v
- Number.- Returns:
- a
float
value in the interval[0, 1]
.
-
makeLong
public static long makeLong(int v, int w)
Creates along
from twoint
values.- Parameters:
v
- Number (high order bits).w
- Number (low order bits).- Returns:
- a
long
value.
-
makeInt
@Deprecated public static int makeInt(long v)
Deprecated.Since version 1.2. Method has become obsolete following RNG-57.Creates anint
from along
.- Parameters:
v
- Number.- Returns:
- an
int
value made from the "xor" of thehigh order bits
andlow order bits
ofv
.
-
extractHi
public static int extractHi(long v)
Creates anint
from along
, using the high order bits.The returned value is such that if
vL = extractLo(v); vH = extractHi(v);
then
v
is equal tomakeLong(vH, vL)
.- Parameters:
v
- Number.- Returns:
- an
int
value made from the most significant bits ofv
.
-
extractLo
public static int extractLo(long v)
Creates anint
from along
, using the low order bits.The returned value is such that if
vL = extractLo(v); vH = extractHi(v);
then
v
is equal tomakeLong(vH, vL)
.- Parameters:
v
- Number.- Returns:
- an
int
value made from the least significant bits ofv
.
-
makeByteArray
public static byte[] makeByteArray(long v)
Splits along
into 8 bytes.- Parameters:
v
- Value.- Returns:
- the bytes that compose the given value (least-significant byte first).
-
makeLong
public static long makeLong(byte[] input)
Creates along
from 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
public static byte[] makeByteArray(long[] input)
Splits an array oflong
values into a sequence of bytes. This method callsmakeByteArray(long)
for each element of theinput
.- Parameters:
input
- Input.- Returns:
- an array of bytes.
-
makeLongArray
public static long[] makeLongArray(byte[] input)
Creates an array oflong
values 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.length
is not a multiple of 8.
-
makeByteArray
public static byte[] makeByteArray(int v)
Splits anint
into 4 bytes.- Parameters:
v
- Value.- Returns:
- the bytes that compose the given value (least-significant byte first).
-
makeInt
public static int makeInt(byte[] input)
Creates anint
from 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
public static byte[] makeByteArray(int[] input)
Splits an array ofint
values into a sequence of bytes. This method callsmakeByteArray(int)
for each element of theinput
.- Parameters:
input
- Input.- Returns:
- an array of bytes.
-
makeIntArray
public static int[] makeIntArray(byte[] input)
Creates an array ofint
values 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.length
is not a multiple of 4.
-
-