Class UnsignedLong
java.lang.Object
java.lang.Number
com.google.common.primitives.UnsignedLong
- All Implemented Interfaces:
Serializable
,Comparable<UnsignedLong>
@GwtCompatible(serializable=true)
public final class UnsignedLong
extends Number
implements Comparable<UnsignedLong>, Serializable
A wrapper class for unsigned
long
values, supporting arithmetic operations.
In some cases, when speed is more important than code readability, it may be faster simply to
treat primitive long
values as unsigned, using the methods from UnsignedLongs
.
See the Guava User Guide article on unsigned primitive utilities.
- Since:
- 11.0
- Author:
- Louis Wasserman, Colin Evans
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final UnsignedLong
static final UnsignedLong
static final UnsignedLong
-
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thisUnsignedLong
as aBigInteger
.int
dividedBy
(UnsignedLong val) Returns the result of dividing this byval
.double
Returns the value of thisUnsignedLong
as adouble
, analogous to a widening primitive conversion fromlong
todouble
, and correctly rounded.boolean
float
Returns the value of thisUnsignedLong
as afloat
, analogous to a widening primitive conversion fromlong
tofloat
, and correctly rounded.static UnsignedLong
fromLongBits
(long bits) Returns anUnsignedLong
corresponding to a given bit representation.int
hashCode()
int
intValue()
Returns the value of thisUnsignedLong
as anint
.long
Returns the value of thisUnsignedLong
as along
.minus
(UnsignedLong val) Returns the result of subtracting this andval
.mod
(UnsignedLong val) Returns this moduloval
.plus
(UnsignedLong val) Returns the result of adding this andval
.times
(UnsignedLong val) Returns the result of multiplying this andval
.toString()
Returns a string representation of theUnsignedLong
value, in base 10.toString
(int radix) Returns a string representation of theUnsignedLong
value, in baseradix
.static UnsignedLong
valueOf
(long value) Returns anUnsignedLong
representing the same value as the specifiedlong
.static UnsignedLong
Returns anUnsignedLong
holding the value of the specifiedString
, parsed as an unsignedlong
value.static UnsignedLong
Returns anUnsignedLong
holding the value of the specifiedString
, parsed as an unsignedlong
value in the specified radix.static UnsignedLong
valueOf
(BigInteger value) Returns aUnsignedLong
representing the same value as the specifiedBigInteger
.Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
ZERO
-
ONE
-
MAX_VALUE
-
-
Method Details
-
fromLongBits
Returns anUnsignedLong
corresponding to a given bit representation. The argument is interpreted as an unsigned 64-bit value. Specifically, the sign bit ofbits
is interpreted as a normal bit, and all other bits are treated as usual.If the argument is nonnegative, the returned result will be equal to
bits
, otherwise, the result will be equal to2^64 + bits
.To represent decimal constants less than
2^63
, considervalueOf(long)
instead.- Since:
- 14.0
-
valueOf
Returns anUnsignedLong
representing the same value as the specifiedlong
.- Throws:
IllegalArgumentException
- ifvalue
is negative- Since:
- 14.0
-
valueOf
Returns aUnsignedLong
representing the same value as the specifiedBigInteger
. This is the inverse operation ofbigIntegerValue()
.- Throws:
IllegalArgumentException
- ifvalue
is negative orvalue >= 2^64
-
valueOf
Returns anUnsignedLong
holding the value of the specifiedString
, parsed as an unsignedlong
value.- Throws:
NumberFormatException
- if the string does not contain a parsable unsignedlong
value
-
valueOf
Returns anUnsignedLong
holding the value of the specifiedString
, parsed as an unsignedlong
value in the specified radix.- Throws:
NumberFormatException
- if the string does not contain a parsable unsignedlong
value, orradix
is not betweenCharacter.MIN_RADIX
andCharacter.MAX_RADIX
-
plus
Returns the result of adding this andval
. If the result would have more than 64 bits, returns the low 64 bits of the result.- Since:
- 14.0
-
minus
Returns the result of subtracting this andval
. If the result would have more than 64 bits, returns the low 64 bits of the result.- Since:
- 14.0
-
times
Returns the result of multiplying this andval
. If the result would have more than 64 bits, returns the low 64 bits of the result.- Since:
- 14.0
-
dividedBy
Returns the result of dividing this byval
.- Since:
- 14.0
-
mod
-
intValue
-
longValue
Returns the value of thisUnsignedLong
as along
. This is an inverse operation tofromLongBits(long)
.Note that if this
UnsignedLong
holds a value>= 2^63
, the returned value will be equal tothis - 2^64
. -
floatValue
Returns the value of thisUnsignedLong
as afloat
, analogous to a widening primitive conversion fromlong
tofloat
, and correctly rounded.- Specified by:
floatValue
in classNumber
-
doubleValue
Returns the value of thisUnsignedLong
as adouble
, analogous to a widening primitive conversion fromlong
todouble
, and correctly rounded.- Specified by:
doubleValue
in classNumber
-
bigIntegerValue
Returns the value of thisUnsignedLong
as aBigInteger
. -
compareTo
- Specified by:
compareTo
in interfaceComparable<UnsignedLong>
-
hashCode
-
equals
-
toString
-
toString
-