Class UnsignedLong
java.lang.Object
java.lang.Number
com.google.common.primitives.UnsignedLong
- All Implemented Interfaces:
Serializable, Comparable<UnsignedLong>
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
FieldsModifier and TypeFieldDescriptionstatic final UnsignedLongstatic final UnsignedLongstatic final UnsignedLong -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thisUnsignedLongas aBigInteger.intdividedBy(UnsignedLong val) Returns the result of dividing this byval.doubleReturns the value of thisUnsignedLongas adouble, analogous to a widening primitive conversion fromlongtodouble, and correctly rounded.booleanfloatReturns the value of thisUnsignedLongas afloat, analogous to a widening primitive conversion fromlongtofloat, and correctly rounded.static UnsignedLongfromLongBits(long bits) Returns anUnsignedLongcorresponding to a given bit representation.inthashCode()intintValue()Returns the value of thisUnsignedLongas anint.longReturns the value of thisUnsignedLongas 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 theUnsignedLongvalue, in base 10.toString(int radix) Returns a string representation of theUnsignedLongvalue, in baseradix.static UnsignedLongvalueOf(long value) Returns anUnsignedLongrepresenting the same value as the specifiedlong.static UnsignedLongReturns anUnsignedLongholding the value of the specifiedString, parsed as an unsignedlongvalue.static UnsignedLongReturns anUnsignedLongholding the value of the specifiedString, parsed as an unsignedlongvalue in the specified radix.static UnsignedLongvalueOf(BigInteger value) Returns aUnsignedLongrepresenting the same value as the specifiedBigInteger.Methods inherited from class Number
byteValue, shortValue
-
Field Details
-
ZERO
-
ONE
-
MAX_VALUE
-
-
Method Details
-
fromLongBits
Returns anUnsignedLongcorresponding to a given bit representation. The argument is interpreted as an unsigned 64-bit value. Specifically, the sign bit ofbitsis 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 anUnsignedLongrepresenting the same value as the specifiedlong.- Throws:
IllegalArgumentException- ifvalueis negative- Since:
- 14.0
-
valueOf
Returns aUnsignedLongrepresenting the same value as the specifiedBigInteger. This is the inverse operation ofbigIntegerValue().- Throws:
IllegalArgumentException- ifvalueis negative orvalue >= 2^64
-
valueOf
Returns anUnsignedLongholding the value of the specifiedString, parsed as an unsignedlongvalue.- Throws:
NumberFormatException- if the string does not contain a parsable unsignedlongvalue
-
valueOf
Returns anUnsignedLongholding the value of the specifiedString, parsed as an unsignedlongvalue in the specified radix.- Throws:
NumberFormatException- if the string does not contain a parsable unsignedlongvalue, orradixis not betweenCharacter.MIN_RADIXandCharacter.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
public long longValue()Returns the value of thisUnsignedLongas along. This is an inverse operation tofromLongBits(long).Note that if this
UnsignedLongholds a value>= 2^63, the returned value will be equal tothis - 2^64. -
floatValue
public float floatValue()Returns the value of thisUnsignedLongas afloat, analogous to a widening primitive conversion fromlongtofloat, and correctly rounded.- Specified by:
floatValuein classNumber
-
doubleValue
public double doubleValue()Returns the value of thisUnsignedLongas adouble, analogous to a widening primitive conversion fromlongtodouble, and correctly rounded.- Specified by:
doubleValuein classNumber
-
bigIntegerValue
Returns the value of thisUnsignedLongas aBigInteger. -
compareTo
- Specified by:
compareToin interfaceComparable<UnsignedLong>
-
hashCode
-
equals
-
toString
-
toString
Returns a string representation of theUnsignedLongvalue, in baseradix. Ifradix < Character.MIN_RADIXorradix > Character.MAX_RADIX, the radix10is used.
-