Class UInt128
java.lang.Object
org.apache.commons.statistics.descriptive.UInt128
A mutable 128-bit unsigned integer.
This is a specialised class to implement an accumulator of long values
generated by squaring int values.
- Since:
- 1.1
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidAdds the value in-place.(package private) voidaddPositive(long x) Adds the value in place.(package private) static UInt128create()Create an instance.(package private) longhi64()Return the higher 64-bits as alongvalue.(package private) intlo32()Return the low 32-bits as anintvalue.(package private) longlo64()Return the lower 64-bits as alongvalue.(package private) intmid32()Return the middle 32-bits as anintvalue.(package private) static UInt128Create an instance of theUInt96value.(package private) UInt128Subtracts the value.(package private) BigIntegerConvert to a BigInteger.(package private) doubletoDouble()Convert to adouble.(package private) intConvert to anint; throwing an exception if the value overflows anint.(package private) longConvert to along; throwing an exception if the value overflows along.(package private) UInt128unsignedMultiply(int x) Multiply by the unsigned value.
-
Field Details
-
MASK32
private static final long MASK32Mask for the lower 32-bits of a long.- See Also:
-
d
private int dbits 32-1 (low 32-bits). -
c
private int cbits 64-33. -
ab
private long abbits 128-65.
-
-
Constructor Details
-
UInt128
private UInt128()Create an instance. -
UInt128
private UInt128(long hi, int mid, int lo) Create an instance using a direct binary representation.- Parameters:
hi- High 64-bits.mid- Middle 32-bits.lo- Low 32-bits.
-
UInt128
UInt128(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
-
of
-
addPositive
void addPositive(long x) Adds the value in place. It is assumed to be positive, for example the square of anintvalue. However no check is performed for a negative value.Note: This addition handles -9223372036854775808L as an unsigned value of 2^63.
- Parameters:
x- Value.
-
add
-
unsignedMultiply
Multiply by the unsigned value. Any overflow bits are lost.- Parameters:
x- Value.- Returns:
- the product
-
subtract
-
toBigInteger
-
toDouble
double toDouble()Convert to adouble.- Returns:
- the value
-
toIntExact
int toIntExact()Convert to anint; throwing an exception if the value overflows anint.- Returns:
- the value
- Throws:
ArithmeticException- if the value overflows anint.- See Also:
-
toLongExact
long toLongExact()Convert to along; throwing an exception if the value overflows along.- Returns:
- the value
- Throws:
ArithmeticException- if the value overflows along.
-
lo64
long lo64()Return the lower 64-bits as alongvalue.- Returns:
- bits 64-1
-
lo32
int lo32()Return the low 32-bits as anintvalue.- Returns:
- bits 32-1
-
mid32
int mid32()Return the middle 32-bits as anintvalue.- Returns:
- bits 64-33
-
hi64
long hi64()Return the higher 64-bits as alongvalue.- Returns:
- bits 128-65
-