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
FieldsModifier and TypeFieldDescriptionprivate longhigh 64-bits.private longlow 64-bits.private static final longMask for the lower 32-bits of a long.private static final long2^53. -
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) doubledivideToDouble(long n) Divide by the countn, returning the value as adouble.(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:
-
TWO_POW_53
private static final long TWO_POW_532^53.- 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
-
of
Create an instance of thelongvalue.- Parameters:
x- Value.- Returns:
- the instance
-
add
void add(long x) Adds the value.- Parameters:
x- Value.
-
add
-
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
-
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
-
divideToDouble
double divideToDouble(long n) Divide by the countn, returning the value as adouble.- Parameters:
n- Count.- Returns:
- the quotient
-
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:
-