Class Int128
- java.lang.Object
-
- org.apache.commons.statistics.descriptive.Int128
-
final class Int128 extends java.lang.ObjectA mutable 128-bit signed integer.This is a specialised class to implement an accumulator of
longvalues.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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidadd(long x)Adds the value.(package private) voidadd(Int128 x)Adds 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) UInt128squareLow()Compute the square of the low 64-bits of this number.(package private) java.math.BigIntegertoBigInteger()Convert to a BigInteger.(package private) org.apache.commons.numbers.core.DDtoDD()Convert to a double-double.(package private) doubletoDouble()Convert to adouble.(package private) inttoIntExact()Convert to anint; throwing an exception if the value overflows anint.(package private) longtoLongExact()Convert to along; throwing an exception if the value overflows along.
-
-
-
Field Detail
-
MASK32
private static final long MASK32
Mask for the lower 32-bits of a long.- See Also:
- Constant Field Values
-
lo
private long lo
low 64-bits.
-
hi
private long hi
high 64-bits.
-
-
Constructor Detail
-
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 Detail
-
create
static Int128 create()
Create an instance. The initial value is zero.- Returns:
- the instance
-
of
static Int128 of(long x)
Create an instance of thelongvalue.- Parameters:
x- Value.- Returns:
- the instance
-
add
void add(long x)
Adds the value.- Parameters:
x- Value.
-
add
void add(Int128 x)
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
java.math.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:
java.lang.ArithmeticException- if the value overflows anint.- See Also:
Math.toIntExact(long)
-
toLongExact
long toLongExact()
Convert to along; throwing an exception if the value overflows along.- Returns:
- the value
- Throws:
java.lang.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:
lo64()
-
-