Interface UInt384Value<T extends UInt384Value<T>>
- Type Parameters:
T- The concrete type of the value.
- All Superinterfaces:
Comparable<T>
- All Known Implementing Classes:
BaseUInt384Value,UInt384
A UInt384Value is an unsigned integer value stored with 48 bytes, so whose value can
range between 0 and 2^384-1.
This interface defines operations for value types with a 384-bit precision range. The methods
provided by this interface take parameters of the same type (and also long. This provides
type safety by ensuring calculations cannot mix different UInt384Value types.
Where only a pure numerical 384-bit value is required, UInt384 should be used.
It is strongly advised to extend BaseUInt384Value rather than implementing this
interface directly. Doing so provides type safety in that quantities of different units cannot be
mixed accidentally.
-
Method Summary
Modifier and TypeMethodDescriptionadd(long value) Returns a value that is(this + value).Returns a value that is(this + value).default TaddExact(long value) Returns a value that is(this + value).default TReturns a value that is(this + value).addMod(long value, long modulus) Returns a value equivalent to((this + value) mod modulus).Returns a value equivalent to((this + value) mod modulus).Returns a value equivalent to((this + value) mod modulus).default intReturns the number of bits following and including the highest-order ("leftmost") one-bitdivide(long value) Returns a value that is(this / value).Returns a value that is(this / value).default booleanfitsInt()Returns true if this value fits an intdefault booleanfitsLong()Returns true if this value fits in a long.default intintValue()Returns the value as an int.default booleanisZero()Returns true is this is 0.mod(long modulus) Returns a value that is(this mod modulus).Returns a value that is(this mod modulus).multiply(long value) Returns a value that is(this * value).Returns a value that is(this * value).multiplyMod(long value, long modulus) Returns a value that is((this * value) mod modulus).multiplyMod(long value, UInt384 modulus) Returns a value that is((this * value) mod modulus).multiplyMod(T value, UInt384 modulus) Returns a value that is((this * value) mod modulus).default intReturns the number of zero bits preceding the highest-order ("leftmost") one-bitpow(long exponent) Returns a value that is(this<sup>exponent</sup> mod 2<sup>384</sup>)Returns a value that is(this<sup>exponent</sup> mod 2<sup>384</sup>)subtract(long value) Returns a value that is(this - value).Returns a value that is(this - value).default TsubtractExact(long value) Returns a value that is(this - value).default TsubtractExact(T value) Returns a value that is(this - value).default BigIntegerReturns this value as aBigInteger.org.apache.tuweni.bytes.Bytes48toBytes()Returns the value as bytesdefault StringReturns the decimal representation of this value as a String.default StringThis value represented as an hexadecimal string.default longtoLong()Returns this value as a long.org.apache.tuweni.bytes.BytesRetuns the value as bytes without any leading zero bytes.default StringReturns this value represented as a minimal hexadecimal string (without any leading zero).Convert this value to aUInt384.Methods inherited from interface java.lang.Comparable
compareTo
-
Method Details
-
isZero
default boolean isZero()Returns true is this is 0.- Returns:
- True if this is the value 0.
-
add
Returns a value that is(this + value).- Parameters:
value- The amount to be added to this value.- Returns:
this + value
-
addExact
Returns a value that is(this + value).- Parameters:
value- the amount to be added to this value- Returns:
this + value- Throws:
ArithmeticException- if the result of the addition overflows
-
add
Returns a value that is(this + value).- Parameters:
value- The amount to be added to this value.- Returns:
this + value
-
addExact
Returns a value that is(this + value).- Parameters:
value- the amount to be added to this value- Returns:
this + value- Throws:
ArithmeticException- if the result of the addition overflows
-
addMod
Returns a value equivalent to((this + value) mod modulus).- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus- Throws:
ArithmeticException-modulus== 0.
-
addMod
Returns a value equivalent to((this + value) mod modulus).- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus- Throws:
ArithmeticException-modulus== 0.
-
addMod
Returns a value equivalent to((this + value) mod modulus).- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus- Throws:
ArithmeticException-modulus≤ 0.
-
subtract
Returns a value that is(this - value).- Parameters:
value- The amount to be subtracted from this value.- Returns:
this - value
-
subtractExact
Returns a value that is(this - value).- Parameters:
value- the amount to be subtracted to this value- Returns:
this - value- Throws:
ArithmeticException- if the result of the addition overflows
-
subtract
Returns a value that is(this - value).- Parameters:
value- The amount to be subtracted from this value.- Returns:
this - value
-
subtractExact
Returns a value that is(this - value).- Parameters:
value- the amount to be subtracted to this value- Returns:
this - value- Throws:
ArithmeticException- if the result of the addition overflows
-
multiply
Returns a value that is(this * value).- Parameters:
value- The amount to multiply this value by.- Returns:
this * value
-
multiply
Returns a value that is(this * value).- Parameters:
value- The amount to multiply this value by.- Returns:
this * value- Throws:
ArithmeticException-value< 0.
-
multiplyMod
Returns a value that is((this * value) mod modulus).- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus- Throws:
ArithmeticException-value< 0 ormodulus== 0.
-
multiplyMod
Returns a value that is((this * value) mod modulus).- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus- Throws:
ArithmeticException-value< 0 ormodulus== 0.
-
multiplyMod
Returns a value that is((this * value) mod modulus).- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus- Throws:
ArithmeticException-value< 0 ormodulus≤ 0.
-
divide
Returns a value that is(this / value).- Parameters:
value- The amount to divide this value by.- Returns:
this / value- Throws:
ArithmeticException-value== 0.
-
divide
Returns a value that is(this / value).- Parameters:
value- The amount to divide this value by.- Returns:
this / value- Throws:
ArithmeticException-value≤ 0.
-
pow
Returns a value that is(this<sup>exponent</sup> mod 2<sup>384</sup>)This calculates an exponentiation over the modulus of
2^384.Note that
exponentis anUInt384rather than of the typeT.- Parameters:
exponent- The exponent to which this value is to be raised.- Returns:
this<sup>exponent</sup> mod 2<sup>384</sup>
-
pow
Returns a value that is(this<sup>exponent</sup> mod 2<sup>384</sup>)This calculates an exponentiation over the modulus of
2^384.- Parameters:
exponent- The exponent to which this value is to be raised.- Returns:
this<sup>exponent</sup> mod 2<sup>384</sup>
-
mod
Returns a value that is(this mod modulus).- Parameters:
modulus- The modulus.- Returns:
this mod modulus.- Throws:
ArithmeticException-modulus== 0.
-
mod
Returns a value that is(this mod modulus).- Parameters:
modulus- The modulus.- Returns:
this mod modulus.- Throws:
ArithmeticException-modulus≤ 0.
-
fitsInt
default boolean fitsInt()Returns true if this value fits an int- Returns:
- True if this value fits a java
int(i.e. is less or equal toInteger.MAX_VALUE).
-
intValue
default int intValue()Returns the value as an int.- Returns:
- This value as a java
intassuming it is small enough to fit anint. - Throws:
ArithmeticException- If the value does not fit anint, that is if!fitsInt().
-
fitsLong
default boolean fitsLong()Returns true if this value fits in a long.- Returns:
- True if this value fits a java
long(i.e. is less or equal toLong.MAX_VALUE).
-
toLong
default long toLong()Returns this value as a long.- Returns:
- This value as a java
longassuming it is small enough to fit along. - Throws:
ArithmeticException- If the value does not fit along, that is if!fitsLong().
-
toBigInteger
Returns this value as aBigInteger.- Returns:
- This value as a
BigInteger.
-
toHexString
This value represented as an hexadecimal string.Note that this representation includes all the 48 underlying bytes, no matter what the integer actually represents (in other words, it can have many leading zeros). For a shorter representation that don't include leading zeros, use
toShortHexString().- Returns:
- This value represented as an hexadecimal string.
-
toShortHexString
Returns this value represented as a minimal hexadecimal string (without any leading zero).- Returns:
- This value represented as a minimal hexadecimal string (without any leading zero).
-
toUInt384
UInt384 toUInt384()Convert this value to aUInt384.- Returns:
- This value as a
UInt384.
-
toBytes
org.apache.tuweni.bytes.Bytes48 toBytes()Returns the value as bytes- Returns:
- The value as bytes.
-
toMinimalBytes
org.apache.tuweni.bytes.Bytes toMinimalBytes()Retuns the value as bytes without any leading zero bytes.- Returns:
- The value as bytes without any leading zero bytes.
-
numberOfLeadingZeros
default int numberOfLeadingZeros()Returns the number of zero bits preceding the highest-order ("leftmost") one-bit- Returns:
- the number of zero bits preceding the highest-order ("leftmost") one-bit in the binary representation of this value, or 384 if the value is equal to zero.
-
bitLength
default int bitLength()Returns the number of bits following and including the highest-order ("leftmost") one-bit- Returns:
- The number of bits following and including the highest-order ("leftmost") one-bit in the binary representation of this value, or zero if all bits are zero.
-
toDecimalString
Returns the decimal representation of this value as a String.- Returns:
- the decimal representation of this value as a String.
-