Class Int128
java.lang.Object
org.apache.commons.statistics.descriptive.Int128
A mutable 128-bit signed integer.
This is a specialised class to implement an accumulator of long values.
Note: This number uses a signed long integer representation of:
value = 264 * hi64 + lo64
If the high value is zero then the low value is the long representation of the number including the sign bit. Otherwise the low value corresponds to a correction term for the scaled high value which contains the sign-bit of the number.
- Since:
- 1.1
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidadd(long x) Adds the value.(package private) voidAdds the value.(package private) static Int128create()Create an instance.(package private) longhi64()Return the higher 64-bits as alongvalue.(package private) longlo64()Return the lower 64-bits as alongvalue.(package private) static Int128of(long x) Create an instance of thelongvalue.(package private) UInt128Compute the square of the low 64-bits of this number.(package private) BigIntegerConvert to a BigInteger.(package private) org.apache.commons.numbers.core.DDtoDD()Convert to a double-double.(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.
-
Field Details
-
MASK32
private static final long MASK32Mask for the lower 32-bits of a long.- See Also:
-
lo
private long lolow 64-bits. -
hi
private long hihigh 64-bits.
-
-
Constructor Details
-
Int128
private Int128()Create an instance. -
Int128
private Int128(long x) Create an instance.- Parameters:
x- Value.
-
Int128
Int128(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
Create an instance. The initial value is zero.- Returns:
- the instance
-
of
Create an instance of thelongvalue.- Parameters:
x- Value.- Returns:
- the instance
-
add
void add(long x) Adds the value.- Parameters:
x- Value.
-
add
Adds the value.- Parameters:
x- Value.
-
squareLow
UInt128 squareLow()Compute the square of the low 64-bits of this number.Warning: This ignores the upper 64-bits. Use with caution.
- Returns:
- the square
-
toBigInteger
BigInteger toBigInteger()Convert to a BigInteger.- Returns:
- the value
-
toDouble
double toDouble()Convert to adouble.- Returns:
- the value
-
toDD
org.apache.commons.numbers.core.DD toDD()Convert to a double-double.- 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.If the high value is zero then the low value is the long representation of the number including the sign bit. Otherwise this value corresponds to a correction term for the scaled high value which contains the sign-bit of the number (see
Int128).- Returns:
- the low 64-bits
-
hi64
long hi64()Return the higher 64-bits as alongvalue.- Returns:
- the high 64-bits
- See Also:
-