public final class UnsignedInt128 extends Object implements Comparable<UnsignedInt128>, Serializable
Decimal128
and SignedInt128
. This object is much faster and
more compact than BigInteger, but has many limitations below.
Modifier and Type | Field and Description |
---|---|
static int |
BYTE_SIZE
Number of bytes to store this object.
|
static int |
INT_COUNT
Number of ints to store this object.
|
static int |
MAX_DIGITS
Can hold up to 10^38.
|
static UnsignedInt128 |
MAX_VALUE
Maximum value that can be represented in this class.
|
static UnsignedInt128 |
MIN_VALUE
Minimum value that can be represented in this class.
|
static UnsignedInt128 |
TEN_TO_THIRTYEIGHT
A special value representing 10**38.
|
Constructor and Description |
---|
UnsignedInt128()
Creates an instance that represents zero.
|
UnsignedInt128(BigInteger bigInt)
Constructs from the given BigInteger
|
UnsignedInt128(char[] str,
int offset,
int length)
Constructs from the given string with given offset and length.
|
UnsignedInt128(int v0,
int v1,
int v2,
int v3)
Creates an instance that has the given values.
|
UnsignedInt128(long v)
Constructs from the given long value.
|
UnsignedInt128(String str)
Constructs from the given string.
|
UnsignedInt128(UnsignedInt128 o)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
UnsignedInt128 |
addConstructive(UnsignedInt128 right)
This version returns the result as a new object, not modifying the give
objects.
|
void |
addDestructive(int r)
Adds the given value to this value.
|
void |
addDestructive(int[] r)
Adds the given value to this value.
|
void |
addDestructive(UnsignedInt128 right)
Adds the given value to this value.
|
void |
addDestructiveScaleTen(UnsignedInt128 right,
short tenScale)
Adds the given value after scaling to this value.
|
long |
asLong()
Returns the value of this object as long, throwing error if the value
exceeds long.
|
protected Object |
clone() |
int |
compareTo(int[] o) |
int |
compareTo(int o0,
int o1,
int o2,
int o3) |
int |
compareTo(UnsignedInt128 o) |
int |
compareToScaleTen(UnsignedInt128 o,
short tenScale)
Compares with the given object after scaling up/down it for 10**scaleUp.
|
UnsignedInt128 |
decrementConstructive()
This version returns the result as a new object, not modifying the give
objects.
|
void |
decrementDestructive()
Subtracts one from this value.
|
static byte |
difference(UnsignedInt128 left,
UnsignedInt128 right,
UnsignedInt128 result)
Calculates absolute difference (remember that this is unsigned) of left and
right operator.
|
static byte |
differenceScaleTen(UnsignedInt128 left,
UnsignedInt128 right,
UnsignedInt128 result,
short tenScale)
Calculates absolute difference of left and right operator after ten-based
scaling on right.
|
UnsignedInt128 |
divideConstructive(int right)
This version returns the result as a new object, not modifying the give
objects.
|
UnsignedInt128 |
divideConstructive(UnsignedInt128 right,
UnsignedInt128 remainder)
This version returns the result as a new object, not modifying the give
objects.
|
int |
divideDestructive(int right)
Divides this value with the given value.
|
long |
divideDestructive(long right)
Divides this value with the given value.
|
void |
divideDestructive(UnsignedInt128 right,
UnsignedInt128 remainder)
Divides this value with the given value.
|
void |
divideScaleUpTenDestructive(UnsignedInt128 right,
short tenScale,
UnsignedInt128 remainder)
Scale up this object for 10**tenScale and then divides this value with the
given value.
|
boolean |
equals(int o0,
int o1,
int o2,
int o3)
Specialized version.
|
boolean |
equals(Object obj) |
boolean |
equals(UnsignedInt128 o)
Specialized version.
|
boolean |
exceedsTenToThirtyEight()
Returns if we overflowed 10**38, but not 2**128.
|
int |
fastSerializeForHiveDecimal(Decimal128FastBuffer scratch,
byte signum) |
byte |
fastUpdateFromInternalStorage(byte[] internalStorage)
Updates this value from a serialized unscaled
BigInteger representation. |
boolean |
fitsInt32() |
byte |
getCount() |
char[] |
getDigitsArray(int[] meta)
Similar to
toFormalString() but returns an array of digits
instead of string. |
static int |
getIntsPerElement(int precision)
Determines the number of ints to store one value.
|
int[] |
getV() |
int |
getV0() |
int |
getV1() |
int |
getV2() |
int |
getV3() |
int |
hashCode() |
UnsignedInt128 |
incrementConstructive()
This version returns the result as a new object, not modifying the give
objects.
|
void |
incrementDestructive()
Adds one to this value.
|
boolean |
isOne() |
boolean |
isZero() |
UnsignedInt128 |
multiplyConstructive(int right)
This version returns the result as a new object, not modifying the give
objects.
|
UnsignedInt128 |
multiplyConstructive(UnsignedInt128 right)
This version returns the result as a new object, not modifying the give
objects.
|
int[] |
multiplyConstructive256(UnsignedInt128 right)
This version returns the result of multiplication as 256bit data.
|
void |
multiplyDestructive(int right)
Multiplies this value with the given integer value.
|
void |
multiplyDestructive(UnsignedInt128 right)
Multiplies this value with the given value.
|
void |
multiplyScaleDownTenDestructive(UnsignedInt128 right,
short tenScale)
Multiply this value with the given value, followed by ten-based scale down.
|
void |
multiplyShiftDestructive(UnsignedInt128 right,
short rightShifts)
Multiplies this value with the given value, followed by right bit shifts to
scale it back to this object.
|
void |
scaleDownFiveDestructive(short fiveScale)
Scale down the value for 5**tenScale (this := this / 5**tenScale).
|
void |
scaleDownTenDestructive(short tenScale)
Scale down the value for 10**tenScale (this := this / 10**tenScale).
|
void |
scaleUpFiveDestructive(short fiveScale)
Scale up the value for 5**tenScale (this := this * 5**tenScale).
|
void |
scaleUpTenDestructive(short tenScale)
Scale up the value for 10**tenScale (this := this * 10**tenScale).
|
void |
serializeTo(int[] array,
int offset,
int precision)
Serialize this object to the given array, putting the required number of
ints for the given precision.
|
void |
serializeTo(IntBuffer buf,
int precision)
Serialize this object to the given ByteBuffer, putting the required number
of ints for the given precision.
|
void |
serializeTo128(int[] array,
int offset)
Serialize this object to the given array, putting 128 bits data (full
ranges).
|
void |
serializeTo128(IntBuffer buf)
Serialize this object to the given ByteBuffer, putting 128 bits data (full
ranges).
|
void |
serializeTo32(int[] array,
int offset)
Serialize this object to the given array, putting only 32 bits data.
|
void |
serializeTo32(IntBuffer buf)
Serialize this object to the given ByteBuffer, putting only 32 bits data.
|
void |
serializeTo64(int[] array,
int offset)
Serialize this object to the given array, putting only 64 bits data.
|
void |
serializeTo64(IntBuffer buf)
Serialize this object to the given ByteBuffer, putting only 64 bits data.
|
void |
serializeTo96(int[] array,
int offset)
Serialize this object to the given array, putting only 96 bits data.
|
void |
serializeTo96(IntBuffer buf)
Serialize this object to the given ByteBuffer, putting only 96 bits data.
|
void |
setCount(byte count)
This setter is only for de-serialization, should not be used otherwise.
|
void |
setV(int[] v)
This setter is only for de-serialization, should not be used otherwise.
|
void |
setV0(int val)
Setter for v0.
|
void |
setV1(int val)
Setter for v1.
|
void |
setV2(int val)
Setter for v2.
|
void |
setV3(int val)
Setter for v3.
|
UnsignedInt128 |
shiftLeftConstructive(int bits)
This version returns the result as a new object, not modifying the give
objects.
|
void |
shiftLeftDestructive(int bits)
Left-shift for the given number of bits.
|
void |
shiftLeftDestructiveCheckOverflow(int bits)
Left-shift for the given number of bits.
|
UnsignedInt128 |
shiftRightConstructive(int bits,
boolean roundUp)
This version returns the result as a new object, not modifying the give
objects.
|
void |
shiftRightDestructive(int bits,
boolean roundUp)
Right-shift for the given number of bits.
|
UnsignedInt128 |
subtractConstructive(UnsignedInt128 right)
This version returns the result as a new object, not modifying the give
objects.
|
void |
subtractDestructive(int[] r)
Subtracts the given value from this value.
|
void |
subtractDestructive(UnsignedInt128 right)
Subtracts the given value from this value.
|
void |
throwIfExceedsTenToThirtyEight()
Used to check overflows.
|
BigInteger |
toBigIntegerSlow()
Convert this object to
BigInteger . |
String |
toFormalString()
Returns the formal string representation of this value.
|
String |
toString() |
void |
update(BigInteger bigInt)
Updates the value of this object from the given
BigInteger . |
void |
update(char[] str,
int offset,
int length)
Updates the value of this object from the given string with given offset
and length.
|
void |
update(int[] array,
int offset,
int precision)
Updates the value of this object by reading from the given array, using the
required number of ints for the given precision.
|
void |
update(IntBuffer buf,
int precision)
Updates the value of this object by reading from ByteBuffer, using the
required number of ints for the given precision.
|
void |
update(int v0,
int v1,
int v2,
int v3)
Updates the value of this object with the given values.
|
void |
update(long v)
Updates the value of this object with the given long value.
|
void |
update(String str)
Updates the value of this object with the given string.
|
void |
update(UnsignedInt128 o)
Copy from the given object.
|
void |
update128(int[] array,
int offset)
Updates the value of this object by reading from the given array, receiving
128 bits data (full ranges).
|
void |
update128(IntBuffer buf)
Updates the value of this object by reading from ByteBuffer, receiving 128
bits data (full ranges).
|
void |
update32(int[] array,
int offset)
Updates the value of this object by reading from the given array, receiving
only 32 bits data.
|
void |
update32(IntBuffer buf)
Updates the value of this object by reading from ByteBuffer, receiving only
32 bits data.
|
void |
update64(int[] array,
int offset)
Updates the value of this object by reading from the given array, receiving
only 64 bits data.
|
void |
update64(IntBuffer buf)
Updates the value of this object by reading from ByteBuffer, receiving only
64 bits data.
|
void |
update96(int[] array,
int offset)
Updates the value of this object by reading from the given array, receiving
only 96 bits data.
|
void |
update96(IntBuffer buf)
Updates the value of this object by reading from ByteBuffer, receiving only
96 bits data.
|
void |
zeroClear()
Make the value to zero.
|
public static final int INT_COUNT
public static final int BYTE_SIZE
public static final int MAX_DIGITS
public static final UnsignedInt128 MAX_VALUE
public static final UnsignedInt128 MIN_VALUE
public static final UnsignedInt128 TEN_TO_THIRTYEIGHT
public UnsignedInt128()
public UnsignedInt128(UnsignedInt128 o)
o
- The instance to copy frompublic UnsignedInt128(int v0, int v1, int v2, int v3)
v0
- v0v1
- v1v2
- v2v3
- v3public UnsignedInt128(long v)
v
- long valuepublic UnsignedInt128(String str)
str
- stringpublic UnsignedInt128(char[] str, int offset, int length)
str
- stringoffset
- offsetlength
- lengthpublic UnsignedInt128(BigInteger bigInt)
bigInt
- java BigIntegerpublic static int getIntsPerElement(int precision)
precision
- precision (0-38)public void update(BigInteger bigInt)
BigInteger
.
Only positive BigIntegers are expected and behavior is undefined for
negative BigIntegers.bigInt
- java BigIntegerpublic int getV0()
public int getV1()
public int getV2()
public int getV3()
public void setV0(int val)
val
- value to setpublic void setV1(int val)
val
- value to setpublic void setV2(int val)
val
- value to setpublic void setV3(int val)
val
- value to setpublic boolean exceedsTenToThirtyEight()
public void throwIfExceedsTenToThirtyEight()
UnsignedInt128
itself
because this overflow semantics is Decimal's. (throws - but not a checked
exception) ArithmeticException if this value is equal to or exceed 10**38.public long asLong()
public void zeroClear()
public boolean isZero()
public boolean isOne()
public boolean fitsInt32()
public void update(UnsignedInt128 o)
o
- The instance to copy frompublic void update(long v)
v
- long valuepublic void update(int v0, int v1, int v2, int v3)
v0
- v0v1
- v1v2
- v2v3
- v3public void update(IntBuffer buf, int precision)
buf
- ByteBuffer to read values fromprecision
- 0 to 38. Decimal digits.public void update128(IntBuffer buf)
buf
- ByteBuffer to read values frompublic void update96(IntBuffer buf)
buf
- ByteBuffer to read values frompublic void update64(IntBuffer buf)
buf
- ByteBuffer to read values frompublic void update32(IntBuffer buf)
buf
- ByteBuffer to read values frompublic void update(int[] array, int offset, int precision)
array
- array to read values fromoffset
- offset of the long arrayprecision
- 0 to 38. Decimal digits.public void update128(int[] array, int offset)
array
- array to read values fromoffset
- offset of the long arraypublic void update96(int[] array, int offset)
array
- array to read values fromoffset
- offset of the long arraypublic void update64(int[] array, int offset)
array
- array to read values fromoffset
- offset of the long arraypublic void update32(int[] array, int offset)
array
- array to read values fromoffset
- offset of the long arraypublic void update(String str)
str
- stringpublic void update(char[] str, int offset, int length)
str
- stringoffset
- offsetlength
- lengthpublic void serializeTo(IntBuffer buf, int precision)
buf
- ByteBuffer to write values toprecision
- 0 to 38. Decimal digits.public void serializeTo128(IntBuffer buf)
buf
- ByteBuffer to write values topublic void serializeTo96(IntBuffer buf)
buf
- ByteBuffer to write values topublic void serializeTo64(IntBuffer buf)
buf
- ByteBuffer to write values topublic void serializeTo32(IntBuffer buf)
buf
- ByteBuffer to write values topublic void serializeTo(int[] array, int offset, int precision)
array
- array to write values tooffset
- offset of the int arrayprecision
- 0 to 38. Decimal digits.public void serializeTo128(int[] array, int offset)
array
- array to write values tooffset
- offset of the int arraypublic void serializeTo96(int[] array, int offset)
array
- array to write values tooffset
- offset of the int arraypublic void serializeTo64(int[] array, int offset)
array
- array to write values tooffset
- offset of the int arraypublic void serializeTo32(int[] array, int offset)
array
- array to write values tooffset
- offset of the int arraypublic int compareTo(UnsignedInt128 o)
compareTo
in interface Comparable<UnsignedInt128>
public int compareTo(int[] o)
o
- the object to be compared.compareTo(UnsignedInt128)
public int compareTo(int o0, int o1, int o2, int o3)
o0
- o0o1
- o1o2
- o2o3
- o3compareTo(UnsignedInt128)
public int compareToScaleTen(UnsignedInt128 o, short tenScale)
Decimal128
.o
- the object to compare withtenScale
- power of 10 to scale up (if positive) or down (if negative) the
given object.public boolean equals(UnsignedInt128 o)
o
- the object to compare withequals(Object)
public boolean equals(int o0, int o1, int o2, int o3)
o0
- o0o1
- o1o2
- o2o3
- o3equals(Object)
protected Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public BigInteger toBigIntegerSlow()
BigInteger
. Do not use this method in a
performance sensitive place.public String toFormalString()
toString()
, this method returns a string that
can be used to re-construct this object. Remember, toString() is only for
debugging.public char[] getDigitsArray(int[] meta)
toFormalString()
but returns an array of digits
instead of string. The length of the array and the count of trailing
zeros are returned in the array passed at first and second positions
respectively.meta
- Array of size two that is populated with length of the returned array
and the count of trailing zeros.NullPointerException
- if meta is null.ArrayIndexOutOfBoundsException
- if meta is less than size two.public void addDestructive(UnsignedInt128 right)
right
- the value to addpublic void addDestructive(int[] r)
r
- the value to addpublic void addDestructive(int r)
r
- the value to addpublic void incrementDestructive()
public void decrementDestructive()
public void addDestructiveScaleTen(UnsignedInt128 right, short tenScale)
right
- the value to addtenScale
- number of ten-based scaling. could be either positive or negative.public void subtractDestructive(UnsignedInt128 right)
right
- the value to subtractpublic void subtractDestructive(int[] r)
r
- the value to subtractpublic static byte difference(UnsignedInt128 left, UnsignedInt128 right, UnsignedInt128 result)
result := abs (left - right)
This is the core
implementation of subtract and signed add.left
- left operandright
- right operandresult
- the object to receive the result. can be same object as left or
right.public static byte differenceScaleTen(UnsignedInt128 left, UnsignedInt128 right, UnsignedInt128 result, short tenScale)
result := abs (left - (right * 10**tenScale))
This is the core
implementation of subtract.left
- left operandright
- right operandresult
- the object to receive the result. can be same object as left or
right.tenScale
- number of ten-based scaling. could be either positive or negative.public void multiplyDestructive(int right)
right
- the value to multiplypublic void multiplyDestructive(UnsignedInt128 right)
right
- the value to multiplypublic void multiplyShiftDestructive(UnsignedInt128 right, short rightShifts)
right
- the value to multiplyrightShifts
- the number of right-shifts after multiplicationpublic void multiplyScaleDownTenDestructive(UnsignedInt128 right, short tenScale)
right
- right operandtenScale
- distance to scale downpublic void divideDestructive(UnsignedInt128 right, UnsignedInt128 remainder)
right
- the value to divideremainder
- object to receive remainderpublic void divideScaleUpTenDestructive(UnsignedInt128 right, short tenScale, UnsignedInt128 remainder)
right
- the value to dividetenScale
- ten-based scale up distanceremainder
- object to receive remainderpublic int divideDestructive(int right)
right
- the value to dividepublic long divideDestructive(long right)
right
- the value to dividepublic void shiftRightDestructive(int bits, boolean roundUp)
bits
- the number of bits. must be positiveroundUp
- whether to round up the most significant bit that was discardedpublic void shiftLeftDestructive(int bits)
bits
- the number of bits. must be positivepublic void shiftLeftDestructiveCheckOverflow(int bits)
bits
- the number of bits. must be positivepublic void scaleDownTenDestructive(short tenScale)
tenScale
- scaling. must be positivepublic void scaleDownFiveDestructive(short fiveScale)
fiveScale
- scaling. must be positivepublic void scaleUpTenDestructive(short tenScale)
tenScale
- scaling. must be positivepublic void scaleUpFiveDestructive(short fiveScale)
fiveScale
- scaling. must be positivepublic UnsignedInt128 addConstructive(UnsignedInt128 right)
right
- right operandpublic UnsignedInt128 incrementConstructive()
public UnsignedInt128 subtractConstructive(UnsignedInt128 right)
right
- right operandpublic UnsignedInt128 decrementConstructive()
public UnsignedInt128 multiplyConstructive(int right)
right
- right operandpublic UnsignedInt128 multiplyConstructive(UnsignedInt128 right)
right
- right operandpublic int[] multiplyConstructive256(UnsignedInt128 right)
right
- right operandpublic UnsignedInt128 divideConstructive(int right)
right
- right operandpublic UnsignedInt128 divideConstructive(UnsignedInt128 right, UnsignedInt128 remainder)
right
- right operandremainder
- object to receive remainderpublic UnsignedInt128 shiftRightConstructive(int bits, boolean roundUp)
bits
- the number of bits. must be positiveroundUp
- whether to round up the most significant bit that was discardedpublic UnsignedInt128 shiftLeftConstructive(int bits)
bits
- the number of bits. must be positivepublic int fastSerializeForHiveDecimal(Decimal128FastBuffer scratch, byte signum)
public byte fastUpdateFromInternalStorage(byte[] internalStorage)
BigInteger
representation.
This is used for fast update of a Decimal128 from a HiveDecimalWritable internal storage.internalStorage
- public int[] getV()
public void setV(int[] v)
public byte getCount()
public void setCount(byte count)
Copyright © 2017 The Apache Software Foundation. All rights reserved.