org.apache.hadoop.hive.common.type
Class UnsignedInt128

java.lang.Object
  extended by org.apache.hadoop.hive.common.type.UnsignedInt128
All Implemented Interfaces:
Serializable, Comparable<UnsignedInt128>

public final class UnsignedInt128
extends Object
implements Comparable<UnsignedInt128>, Serializable

This code was originally written for Microsoft PolyBase. Represents an unsigned 128-bit integer. This is the basis for Decimal128 and SignedInt128. This object is much faster and more compact than BigInteger, but has many limitations below.

See Also:
Serialized Form

Field Summary
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 Summary
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.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INT_COUNT

public static final int INT_COUNT
Number of ints to store this object.

See Also:
Constant Field Values

BYTE_SIZE

public static final int BYTE_SIZE
Number of bytes to store this object.

See Also:
Constant Field Values

MAX_DIGITS

public static final int MAX_DIGITS
Can hold up to 10^38.

See Also:
Constant Field Values

MAX_VALUE

public static final UnsignedInt128 MAX_VALUE
Maximum value that can be represented in this class.


MIN_VALUE

public static final UnsignedInt128 MIN_VALUE
Minimum value that can be represented in this class.


TEN_TO_THIRTYEIGHT

public static final UnsignedInt128 TEN_TO_THIRTYEIGHT
A special value representing 10**38.

Constructor Detail

UnsignedInt128

public UnsignedInt128()
Creates an instance that represents zero.


UnsignedInt128

public UnsignedInt128(UnsignedInt128 o)
Copy constructor.

Parameters:
o - The instance to copy from

UnsignedInt128

public UnsignedInt128(int v0,
                      int v1,
                      int v2,
                      int v3)
Creates an instance that has the given values.

Parameters:
v0 - v0
v1 - v1
v2 - v2
v3 - v3

UnsignedInt128

public UnsignedInt128(long v)
Constructs from the given long value.

Parameters:
v - long value

UnsignedInt128

public UnsignedInt128(String str)
Constructs from the given string.

Parameters:
str - string

UnsignedInt128

public UnsignedInt128(char[] str,
                      int offset,
                      int length)
Constructs from the given string with given offset and length.

Parameters:
str - string
offset - offset
length - length

UnsignedInt128

public UnsignedInt128(BigInteger bigInt)
Constructs from the given BigInteger

Parameters:
bigInt - java BigInteger
Method Detail

getIntsPerElement

public static int getIntsPerElement(int precision)
Determines the number of ints to store one value.

Parameters:
precision - precision (0-38)
Returns:
the number of ints to store one value

update

public void update(BigInteger bigInt)
Updates the value of this object from the given BigInteger. Only positive BigIntegers are expected and behavior is undefined for negative BigIntegers.

Parameters:
bigInt - java BigInteger

getV0

public int getV0()
Returns:
v[0]

getV1

public int getV1()
Returns:
v[1]

getV2

public int getV2()
Returns:
v[2]

getV3

public int getV3()
Returns:
v[3]

setV0

public void setV0(int val)
Setter for v0.

Parameters:
val - value to set

setV1

public void setV1(int val)
Setter for v1.

Parameters:
val - value to set

setV2

public void setV2(int val)
Setter for v2.

Parameters:
val - value to set

setV3

public void setV3(int val)
Setter for v3.

Parameters:
val - value to set

exceedsTenToThirtyEight

public boolean exceedsTenToThirtyEight()
Returns if we overflowed 10**38, but not 2**128. This code is equivalent to CSsNumeric::FGt10_38 in SQLServer (numeric.cpp). However, be aware that the elements are signed ints, not UI4 in SQLServer.

Returns:
whether this value is equal to or larger than 10**38

throwIfExceedsTenToThirtyEight

public void throwIfExceedsTenToThirtyEight()
Used to check overflows. This is NOT used in 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.


asLong

public long asLong()
Returns the value of this object as long, throwing error if the value exceeds long.

Returns:
the value this object represents

zeroClear

public void zeroClear()
Make the value to zero.


isZero

public boolean isZero()
Returns:
whether the value is zero

isOne

public boolean isOne()
Returns:
whether the value is one

fitsInt32

public boolean fitsInt32()
Returns:
whether 32bits int is enough to represent this value

update

public void update(UnsignedInt128 o)
Copy from the given object.

Parameters:
o - The instance to copy from

update

public void update(long v)
Updates the value of this object with the given long value.

Parameters:
v - long value

update

public void update(int v0,
                   int v1,
                   int v2,
                   int v3)
Updates the value of this object with the given values.

Parameters:
v0 - v0
v1 - v1
v2 - v2
v3 - v3

update

public 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.

Parameters:
buf - ByteBuffer to read values from
precision - 0 to 38. Decimal digits.

update128

public void update128(IntBuffer buf)
Updates the value of this object by reading from ByteBuffer, receiving 128 bits data (full ranges).

Parameters:
buf - ByteBuffer to read values from

update96

public void update96(IntBuffer buf)
Updates the value of this object by reading from ByteBuffer, receiving only 96 bits data.

Parameters:
buf - ByteBuffer to read values from

update64

public void update64(IntBuffer buf)
Updates the value of this object by reading from ByteBuffer, receiving only 64 bits data.

Parameters:
buf - ByteBuffer to read values from

update32

public void update32(IntBuffer buf)
Updates the value of this object by reading from ByteBuffer, receiving only 32 bits data.

Parameters:
buf - ByteBuffer to read values from

update

public 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.

Parameters:
array - array to read values from
offset - offset of the long array
precision - 0 to 38. Decimal digits.

update128

public void update128(int[] array,
                      int offset)
Updates the value of this object by reading from the given array, receiving 128 bits data (full ranges).

Parameters:
array - array to read values from
offset - offset of the long array

update96

public void update96(int[] array,
                     int offset)
Updates the value of this object by reading from the given array, receiving only 96 bits data.

Parameters:
array - array to read values from
offset - offset of the long array

update64

public void update64(int[] array,
                     int offset)
Updates the value of this object by reading from the given array, receiving only 64 bits data.

Parameters:
array - array to read values from
offset - offset of the long array

update32

public void update32(int[] array,
                     int offset)
Updates the value of this object by reading from the given array, receiving only 32 bits data.

Parameters:
array - array to read values from
offset - offset of the long array

update

public void update(String str)
Updates the value of this object with the given string.

Parameters:
str - string

update

public void update(char[] str,
                   int offset,
                   int length)
Updates the value of this object from the given string with given offset and length.

Parameters:
str - string
offset - offset
length - length

serializeTo

public void serializeTo(IntBuffer buf,
                        int precision)
Serialize this object to the given ByteBuffer, putting the required number of ints for the given precision.

Parameters:
buf - ByteBuffer to write values to
precision - 0 to 38. Decimal digits.

serializeTo128

public void serializeTo128(IntBuffer buf)
Serialize this object to the given ByteBuffer, putting 128 bits data (full ranges).

Parameters:
buf - ByteBuffer to write values to

serializeTo96

public void serializeTo96(IntBuffer buf)
Serialize this object to the given ByteBuffer, putting only 96 bits data.

Parameters:
buf - ByteBuffer to write values to

serializeTo64

public void serializeTo64(IntBuffer buf)
Serialize this object to the given ByteBuffer, putting only 64 bits data.

Parameters:
buf - ByteBuffer to write values to

serializeTo32

public void serializeTo32(IntBuffer buf)
Serialize this object to the given ByteBuffer, putting only 32 bits data.

Parameters:
buf - ByteBuffer to write values to

serializeTo

public 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.

Parameters:
array - array to write values to
offset - offset of the int array
precision - 0 to 38. Decimal digits.

serializeTo128

public void serializeTo128(int[] array,
                           int offset)
Serialize this object to the given array, putting 128 bits data (full ranges).

Parameters:
array - array to write values to
offset - offset of the int array

serializeTo96

public void serializeTo96(int[] array,
                          int offset)
Serialize this object to the given array, putting only 96 bits data.

Parameters:
array - array to write values to
offset - offset of the int array

serializeTo64

public void serializeTo64(int[] array,
                          int offset)
Serialize this object to the given array, putting only 64 bits data.

Parameters:
array - array to write values to
offset - offset of the int array

serializeTo32

public void serializeTo32(int[] array,
                          int offset)
Serialize this object to the given array, putting only 32 bits data.

Parameters:
array - array to write values to
offset - offset of the int array

compareTo

public int compareTo(UnsignedInt128 o)
Specified by:
compareTo in interface Comparable<UnsignedInt128>

compareTo

public int compareTo(int[] o)
Parameters:
o - the object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
See Also:
compareTo(UnsignedInt128)

compareTo

public int compareTo(int o0,
                     int o1,
                     int o2,
                     int o3)
Parameters:
o0 - o0
o1 - o1
o2 - o2
o3 - o3
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
See Also:
compareTo(UnsignedInt128)

compareToScaleTen

public int compareToScaleTen(UnsignedInt128 o,
                             short tenScale)
Compares with the given object after scaling up/down it for 10**scaleUp. This method is not destructive. Used from Decimal128.

Parameters:
o - the object to compare with
tenScale - power of 10 to scale up (if positive) or down (if negative) the given object.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

equals

public boolean equals(UnsignedInt128 o)
Specialized version.

Parameters:
o - the object to compare with
Returns:
whether this object is equal to the given object
See Also:
equals(Object)

equals

public boolean equals(int o0,
                      int o1,
                      int o2,
                      int o3)
Specialized version.

Parameters:
o0 - o0
o1 - o1
o2 - o2
o3 - o3
Returns:
whether this object is equal to the given object
See Also:
equals(Object)

clone

protected Object clone()
                throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

toBigIntegerSlow

public BigInteger toBigIntegerSlow()
Convert this object to BigInteger. Do not use this method in a performance sensitive place.

Returns:
BigInteger to represent this object

toFormalString

public String toFormalString()
Returns the formal string representation of this value. Unlike the debug string returned by toString(), this method returns a string that can be used to re-construct this object. Remember, toString() is only for debugging.

Returns:
string representation of this value

getDigitsArray

public char[] getDigitsArray(int[] meta)
Similar to 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.

Parameters:
meta - Array of size two that is populated with length of the returned array and the count of trailing zeros.
Returns:
Digits of the this value
Throws:
NullPointerException - if meta is null.
ArrayIndexOutOfBoundsException - if meta is less than size two.

toString

public String toString()
Overrides:
toString in class Object

addDestructive

public void addDestructive(UnsignedInt128 right)
Adds the given value to this value. This version is destructive, meaning it modifies this object.

Parameters:
right - the value to add

addDestructive

public void addDestructive(int[] r)
Adds the given value to this value. This version is destructive, meaning it modifies this object.

Parameters:
r - the value to add

addDestructive

public void addDestructive(int r)
Adds the given value to this value. This version is destructive, meaning it modifies this object.

Parameters:
r - the value to add

incrementDestructive

public void incrementDestructive()
Adds one to this value. This version is destructive, meaning it modifies this object.


decrementDestructive

public void decrementDestructive()
Subtracts one from this value. This version is destructive, meaning it modifies this object.


addDestructiveScaleTen

public void addDestructiveScaleTen(UnsignedInt128 right,
                                   short tenScale)
Adds the given value after scaling to this value. this := this + (right * 10**tenScale). This version is destructive, meaning it modifies this object.

Parameters:
right - the value to add
tenScale - number of ten-based scaling. could be either positive or negative.

subtractDestructive

public void subtractDestructive(UnsignedInt128 right)
Subtracts the given value from this value. In other words, this := this - right. This method will throw overflow exception if right operand is larger than this value. This version is destructive, meaning it modifies this object.

Parameters:
right - the value to subtract

subtractDestructive

public void subtractDestructive(int[] r)
Subtracts the given value from this value. In other words, this := this - right. This method doesn't work if right operand is larger than this value. This version is destructive, meaning it modifies this object.

Parameters:
r - the value to subtract

difference

public static byte difference(UnsignedInt128 left,
                              UnsignedInt128 right,
                              UnsignedInt128 result)
Calculates absolute difference (remember that this is unsigned) of left and right operator. result := abs (left - right) This is the core implementation of subtract and signed add.

Parameters:
left - left operand
right - right operand
result - the object to receive the result. can be same object as left or right.
Returns:
signum of the result. -1 if left was smaller than right, 1 if larger, 0 if same (result is zero).

differenceScaleTen

public 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. result := abs (left - (right * 10**tenScale)) This is the core implementation of subtract.

Parameters:
left - left operand
right - right operand
result - 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.
Returns:
signum of the result. -1 if left was smaller than right, 1 if larger, 0 if same (result is zero).

multiplyDestructive

public void multiplyDestructive(int right)
Multiplies this value with the given integer value. This version is destructive, meaning it modifies this object.

Parameters:
right - the value to multiply

multiplyDestructive

public void multiplyDestructive(UnsignedInt128 right)
Multiplies this value with the given value. This version is destructive, meaning it modifies this object.

Parameters:
right - the value to multiply

multiplyShiftDestructive

public 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. This is used from division. This version is destructive, meaning it modifies this object.

Parameters:
right - the value to multiply
rightShifts - the number of right-shifts after multiplication

multiplyScaleDownTenDestructive

public void multiplyScaleDownTenDestructive(UnsignedInt128 right,
                                            short tenScale)
Multiply this value with the given value, followed by ten-based scale down. This method does the two operations without cutting off, so it preserves accuracy without throwing a wrong overflow exception.

Parameters:
right - right operand
tenScale - distance to scale down

divideDestructive

public void divideDestructive(UnsignedInt128 right,
                              UnsignedInt128 remainder)
Divides this value with the given value. This version is destructive, meaning it modifies this object.

Parameters:
right - the value to divide
remainder - object to receive remainder

divideScaleUpTenDestructive

public void divideScaleUpTenDestructive(UnsignedInt128 right,
                                        short tenScale,
                                        UnsignedInt128 remainder)
Scale up this object for 10**tenScale and then divides this value with the given value. This version is destructive, meaning it modifies this object.

Parameters:
right - the value to divide
tenScale - ten-based scale up distance
remainder - object to receive remainder

divideDestructive

public int divideDestructive(int right)
Divides this value with the given value. This version is destructive, meaning it modifies this object.

Parameters:
right - the value to divide
Returns:
remainder

divideDestructive

public long divideDestructive(long right)
Divides this value with the given value. This version is destructive, meaning it modifies this object.

Parameters:
right - the value to divide
Returns:
remainder

shiftRightDestructive

public void shiftRightDestructive(int bits,
                                  boolean roundUp)
Right-shift for the given number of bits. This version is destructive, meaning it modifies this object.

Parameters:
bits - the number of bits. must be positive
roundUp - whether to round up the most significant bit that was discarded

shiftLeftDestructive

public void shiftLeftDestructive(int bits)
Left-shift for the given number of bits. This method does not throw an error even if overflow happens. This version is destructive, meaning it modifies this object.

Parameters:
bits - the number of bits. must be positive

shiftLeftDestructiveCheckOverflow

public void shiftLeftDestructiveCheckOverflow(int bits)
Left-shift for the given number of bits. This method throws an error even if overflow happens. This version is destructive, meaning it modifies this object.

Parameters:
bits - the number of bits. must be positive

scaleDownTenDestructive

public void scaleDownTenDestructive(short tenScale)
Scale down the value for 10**tenScale (this := this / 10**tenScale). This method rounds-up, eg 44/10=4, 45/10=5. This version is destructive, meaning it modifies this object.

Parameters:
tenScale - scaling. must be positive

scaleDownFiveDestructive

public void scaleDownFiveDestructive(short fiveScale)
Scale down the value for 5**tenScale (this := this / 5**tenScale). This method rounds-up, eg 42/5=8, 43/5=9. This version is destructive, meaning it modifies this object.

Parameters:
fiveScale - scaling. must be positive

scaleUpTenDestructive

public void scaleUpTenDestructive(short tenScale)
Scale up the value for 10**tenScale (this := this * 10**tenScale). Scaling up DOES throw an error when an overflow occurs. For example, 42.scaleUp(1) = 420, 42.scaleUp(40) = ArithmeticException. This version is destructive, meaning it modifies this object.

Parameters:
tenScale - scaling. must be positive

scaleUpFiveDestructive

public void scaleUpFiveDestructive(short fiveScale)
Scale up the value for 5**tenScale (this := this * 5**tenScale). Scaling up DOES throw an error when an overflow occurs. This version is destructive, meaning it modifies this object.

Parameters:
fiveScale - scaling. must be positive

addConstructive

public UnsignedInt128 addConstructive(UnsignedInt128 right)
This version returns the result as a new object, not modifying the give objects.

Parameters:
right - right operand
Returns:
operation result as a new object

incrementConstructive

public UnsignedInt128 incrementConstructive()
This version returns the result as a new object, not modifying the give objects.

Returns:
operation result as a new object

subtractConstructive

public UnsignedInt128 subtractConstructive(UnsignedInt128 right)
This version returns the result as a new object, not modifying the give objects. This method doesn't work if right operand is larger than this value.

Parameters:
right - right operand
Returns:
operation result as a new object

decrementConstructive

public UnsignedInt128 decrementConstructive()
This version returns the result as a new object, not modifying the give objects. This method doesn't work if right operand is larger than this value.

Returns:
operation result as a new object

multiplyConstructive

public UnsignedInt128 multiplyConstructive(int right)
This version returns the result as a new object, not modifying the give objects.

Parameters:
right - right operand
Returns:
operation result as a new object

multiplyConstructive

public UnsignedInt128 multiplyConstructive(UnsignedInt128 right)
This version returns the result as a new object, not modifying the give objects.

Parameters:
right - right operand
Returns:
operation result as a new object

multiplyConstructive256

public int[] multiplyConstructive256(UnsignedInt128 right)
This version returns the result of multiplication as 256bit data.

Parameters:
right - right operand
Returns:
operation result as 256bit data

divideConstructive

public UnsignedInt128 divideConstructive(int right)
This version returns the result as a new object, not modifying the give objects. Note that this method cannot receive remainder. Use destructive version for it.

Parameters:
right - right operand
Returns:
operation result as a new object

divideConstructive

public UnsignedInt128 divideConstructive(UnsignedInt128 right,
                                         UnsignedInt128 remainder)
This version returns the result as a new object, not modifying the give objects.

Parameters:
right - right operand
remainder - object to receive remainder
Returns:
operation result as a new object

shiftRightConstructive

public UnsignedInt128 shiftRightConstructive(int bits,
                                             boolean roundUp)
This version returns the result as a new object, not modifying the give objects.

Parameters:
bits - the number of bits. must be positive
roundUp - whether to round up the most significant bit that was discarded
Returns:
operation result as a new object

shiftLeftConstructive

public UnsignedInt128 shiftLeftConstructive(int bits)
This version returns the result as a new object, not modifying the give objects.

Parameters:
bits - the number of bits. must be positive
Returns:
operation result as a new object

fastSerializeForHiveDecimal

public int fastSerializeForHiveDecimal(Decimal128FastBuffer scratch,
                                       byte signum)

fastUpdateFromInternalStorage

public byte fastUpdateFromInternalStorage(byte[] internalStorage)
Updates this value from a serialized unscaled BigInteger representation. This is used for fast update of a Decimal128 from a HiveDecimalWritable internal storage.

Parameters:
internalStorage -
Returns:

getV

public int[] getV()

setV

public void setV(int[] v)
This setter is only for de-serialization, should not be used otherwise.


getCount

public byte getCount()

setCount

public void setCount(byte count)
This setter is only for de-serialization, should not be used otherwise.



Copyright © 2014 The Apache Software Foundation. All rights reserved.