public class FastHiveDecimalImpl extends FastHiveDecimal
FastHiveDecimal.FastCheckPrecisionScaleStatus| Modifier and Type | Field and Description |
|---|---|
static BigInteger |
BIG_INTEGER_MAX_DECIMAL |
static int |
DECIMAL64_DECIMAL_DIGITS |
static long |
MAX_ABS_DECIMAL64 |
static int |
MAX_DECIMAL_DIGITS |
FAST_SCRATCH_BUFFER_LEN_BIG_INTEGER_BYTES, FAST_SCRATCH_BUFFER_LEN_SERIALIZATION_UTILS_READ, FAST_SCRATCH_BUFFER_LEN_TO_BYTES, FAST_SCRATCH_LONGS_LEN, fast0, fast1, fast2, fastIntegerDigitCount, fastScale, fastSerializationScale, fastSignum, SCRATCH_LONGS_LEN_FAST_SERIALIZATION_UTILS_WRITE, STRING_ENFORCE_PRECISION_OUT_OF_RANGE, STRING_ENFORCE_SCALE_LESS_THAN_EQUAL_PRECISION, STRING_ENFORCE_SCALE_OUT_OF_RANGE| Constructor and Description |
|---|
FastHiveDecimalImpl() |
| Modifier and Type | Method and Description |
|---|---|
static String |
displayBytes(byte[] bytes,
int start,
int length) |
static boolean |
doAddSameScaleSameSign(FastHiveDecimal fastLeft,
FastHiveDecimal fastRight,
FastHiveDecimal fastResult) |
static boolean |
doAddSameScaleSameSign(int resultSignum,
long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
FastHiveDecimal fastResult) |
static boolean |
doBinaryToDecimalConversion(long lowerWord,
long middleWord,
long highWord,
FastHiveDecimal middleWordMultiplier,
FastHiveDecimal highWordMultiplier,
FastHiveDecimal fastResult)
Convert 3 binary words of N bits each to a fast decimal (scale 0).
|
static boolean |
doDecimalToBinaryDivisionRemainder(long dividendFast0,
long dividendFast1,
long dividendFast2,
FastHiveDecimal fastInverseConst,
int quotientIntegerWordNum,
int quotientIntegerDigitNum,
FastHiveDecimal fastMultiplierConst,
long[] scratchLongs)
A helper method that produces a single binary word remainder from a fast decimal (and
quotient).
|
static boolean |
doFastRound(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int roundPower,
int roundingMode,
FastHiveDecimal fastResult) |
static void |
doFastScaleDown(FastHiveDecimal fastDec,
int scaleDown,
FastHiveDecimal fastResult) |
static void |
doFastScaleDown(long fast0,
long fast1,
long fast2,
int scaleDown,
FastHiveDecimal fastResult)
Fast decimal scale down by factor of 10 with NO rounding.
|
static int |
doFastToFormatBytes(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int formatScale,
byte[] scratchBuffer) |
static boolean |
doSubtractSameScaleNoUnderflow(int resultSignum,
FastHiveDecimal fastLeft,
FastHiveDecimal fastRight,
FastHiveDecimal fastResult) |
static boolean |
doSubtractSameScaleNoUnderflow(int resultSignum,
long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
FastHiveDecimal fastResult) |
static boolean |
doSubtractSameScaleNoUnderflow(long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
long[] result) |
static boolean |
fastAdd(FastHiveDecimal fastLeft,
FastHiveDecimal fastRight,
FastHiveDecimal fastResult) |
static boolean |
fastAdd(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftIntegerDigitCount,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightIntegerDigitCount,
int rightScale,
FastHiveDecimal fastResult)
Add the two decimals.
|
static BigDecimal |
fastBigDecimalValue(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
Return a BigDecimal representing the decimal.
|
static int |
fastBigIntegerBytes(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int fastSerializeScale,
long[] scratchLongs,
byte[] buffer) |
static int |
fastBigIntegerBytesScaled(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int serializeScale,
long[] scratchLongs,
byte[] buffer)
Convert decimal to BigInteger binary bytes with a serialize scale, similar to the formatScale
for toFormatString.
|
static int |
fastBigIntegerBytesUnscaled(int fastSignum,
long fast0,
long fast1,
long fast2,
long[] scratchLongs,
byte[] buffer)
Return binary representation of this decimal's BigInteger equivalent unscaled value using the
format that the BigInteger's toByteArray method returns (and the BigInteger constructor
accepts).
|
static BigInteger |
fastBigIntegerValue(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int fastSerializationScale)
Get a BigInteger representing the decimal's digits without a dot.
|
static BigInteger |
fastBigIntegerValueScaled(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int fastSerializationScale) |
static BigInteger |
fastBigIntegerValueUnscaled(int fastSignum,
long fast0,
long fast1,
long fast2) |
static byte |
fastByteValueClip(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale) |
static FastHiveDecimal.FastCheckPrecisionScaleStatus |
fastCheckPrecisionScale(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int maxPrecision,
int maxScale) |
static int |
fastCompareTo(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftScale,
FastHiveDecimal fastRight) |
static int |
fastCompareTo(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightScale) |
static void |
fastDeserialize64(long inputDecimal64Long,
int inputScale,
FastHiveDecimal fastResult) |
static boolean |
fastDivide(FastHiveDecimal fastLeft,
FastHiveDecimal fastRight,
FastHiveDecimal fastResult) |
static boolean |
fastDivide(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftIntegerDigitCount,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightIntegerDigitCount,
int rightScale,
FastHiveDecimal fastResult) |
static double |
fastDoubleValue(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale) |
static boolean |
fastEquals(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftScale,
FastHiveDecimal fastRight) |
static boolean |
fastEquals(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightScale) |
static boolean |
fastExceedsPrecision(long fast0,
long fast1,
long fast2,
int precision) |
static float |
fastFloatValue(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale) |
static void |
fastFractionPortion(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastScale,
FastHiveDecimal fastResult)
Creates fast decimal from the fraction portion of a fast decimal.
|
static int |
fastHashCode(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
This is the original hash code as returned by OldHiveDecimal.
|
static int |
fastHighWordPrecision(long longWord) |
static int |
fastHighWordTrailingZeroCount(long longWord) |
static void |
fastIntegerPortion(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
FastHiveDecimal fastResult)
Creates fast decimal from the integer portion.
|
static int |
fastIntValueClip(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale) |
static boolean |
fastIsByte(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
Is the decimal value a byte? Range -128 to 127.
|
static boolean |
fastIsInt(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
Is the decimal value a int? Range -2,147,483,648 to 2,147,483,647.
|
static boolean |
fastIsLong(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
Is the decimal value a long? Range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
|
static boolean |
fastIsShort(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
Is the decimal value a short? Range -32,768 to 32,767.
|
static boolean |
fastIsValid(FastHiveDecimal fastDec) |
static boolean |
fastIsValid(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale) |
static long |
fastLongValueClip(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale) |
static int |
fastLongWordPrecision(long longWord) |
static int |
fastLongWordTrailingZeroCount(long longWord) |
static boolean |
fastMultiply(FastHiveDecimal fastLeft,
FastHiveDecimal fastRight,
FastHiveDecimal fastResult) |
static boolean |
fastMultiply(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftIntegerDigitCount,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightIntegerDigitCount,
int rightScale,
FastHiveDecimal fastResult) |
static boolean |
fastMultiply5x5HalfWords(FastHiveDecimal fastLeft,
FastHiveDecimal fastRight,
FastHiveDecimal fastResult) |
static boolean |
fastMultiply5x5HalfWords(long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
FastHiveDecimal fastResult)
Fast decimal multiplication on two decimals that have been already scaled and whose results
will fit in 38 digits.
|
static boolean |
fastMultiply5x5HalfWords(long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
long[] result)
Fast decimal multiplication on two decimals that have been already scaled and whose results
will fit in 38 digits.
|
static boolean |
fastMultiply5x6HalfWords(long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
long[] result)
Fast decimal multiplication on two decimals whose results are permitted to go beyond 38 digits
to the maximum possible 76 digits.
|
static boolean |
fastMultiplyFullInternal(FastHiveDecimal fastLeft,
FastHiveDecimal fastRight,
long[] result) |
static boolean |
fastMultiplyFullInternal(long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
long[] result)
Fast decimal multiplication on two decimals whose results are permitted to go beyond 38 digits
to the maximum possible 76 digits.
|
static int |
fastNewFasterHashCode(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
Hash code based on (new) decimal representation.
|
static boolean |
fastPow(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int exponent,
FastHiveDecimal fastResult) |
static void |
fastRaiseInvalidException(FastHiveDecimal fastResult) |
static void |
fastRaiseInvalidException(FastHiveDecimal fastResult,
String parameters) |
static int |
fastRawPrecision(FastHiveDecimal fastDec) |
static int |
fastRawPrecision(int fastSignum,
long fast0,
long fast1,
long fast2) |
static boolean |
fastRemainder(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftIntegerDigitCount,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightIntegerDigitCount,
int rightScale,
FastHiveDecimal fastResult) |
static boolean |
fastRound(FastHiveDecimal fastDec,
int newScale,
int roundingMode,
FastHiveDecimal fastResult) |
static boolean |
fastRound(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int newScale,
int roundingMode,
FastHiveDecimal fastResult) |
static void |
fastRoundFractionalDown(int fastSignum,
long fast0,
long fast1,
long fast2,
int scaleDown,
FastHiveDecimal fastResult)
Fast decimal scale down by factor of 10 with rounding ROUND_DOWN.
|
static boolean |
fastRoundFractionalHalfEven(int fastSignum,
long fast0,
long fast1,
long fast2,
int scaleDown,
FastHiveDecimal fastResult)
Fast decimal scale down by factor of 10 with rounding ROUND_HALF_EVEN.
|
static boolean |
fastRoundFractionalHalfUp(int fastSignum,
long fast0,
long fast1,
long fast2,
int scaleDown,
FastHiveDecimal fastResult)
Fast decimal scale down by factor of 10 with rounding ROUND_HALF_UP.
|
static boolean |
fastRoundFractionalHalfUp5Words(int fastSignum,
long fast0,
long fast1,
long fast2,
long fast3,
long fast4,
int scaleDown,
FastHiveDecimal fastResult)
Fast decimal scale down by factor of 10 with rounding ROUND_HALF_UP.
|
static boolean |
fastRoundFractionalUp(int fastSignum,
long fast0,
long fast1,
long fast2,
int scaleDown,
FastHiveDecimal fastResult)
Fast decimal scale down by factor of 10 with rounding ROUND_UP.
|
static boolean |
fastRoundIntegerDown(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int roundPower,
FastHiveDecimal fastResult)
Fast decimal scale down by factor of 10 with rounding ROUND_DOWN.
|
static boolean |
fastRoundIntegerHalfEven(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int roundPower,
FastHiveDecimal fastResult)
Fast decimal scale down by factor of 10 with rounding ROUND_HALF_EVEN.
|
static boolean |
fastRoundIntegerHalfUp(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int roundPower,
FastHiveDecimal fastResult)
Fast decimal scale down by factor of 10 with rounding ROUND_HALF_UP.
|
static boolean |
fastRoundIntegerUp(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int roundPower,
FastHiveDecimal fastResult)
Fast decimal integer part rounding ROUND_UP.
|
static boolean |
fastScaleByPowerOfTen(FastHiveDecimal fastDec,
int power,
FastHiveDecimal fastResult) |
static boolean |
fastScaleByPowerOfTen(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int power,
FastHiveDecimal fastResult) |
static boolean |
fastScaleDownNoRound(int fastSignum,
long fast0,
long fast1,
long fast2,
int scaleDown,
FastHiveDecimal fastResult)
Fast decimal scale down by factor of 10 and do not allow rounding.
|
static boolean |
fastScaleUp(FastHiveDecimal fastDec,
int scaleUp,
FastHiveDecimal fastResult) |
static boolean |
fastScaleUp(long fast0,
long fast1,
long fast2,
int scaleUp,
FastHiveDecimal fastResult)
Fast decimal scale up by factor of 10.
|
static boolean |
fastSerializationUtilsRead(InputStream inputStream,
int scale,
byte[] scratchBytes,
FastHiveDecimal fastResult)
Deserialize data written in the format used by the SerializationUtils methods
readBigInteger/writeBigInteger and create a decimal using the supplied scale.
|
static boolean |
fastSerializationUtilsWrite(OutputStream outputStream,
int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
long[] scratchLongs)
Write the value of this decimal just like SerializationUtils.writeBigInteger.
|
static long |
fastSerialize64(int scale,
int fastSignum,
long fast1,
long fast0,
int fastScale) |
static boolean |
fastSetFromBigDecimal(BigDecimal bigDecimal,
boolean allowRounding,
FastHiveDecimal fastResult)
Create a fast decimal from a BigDecimal.
|
static boolean |
fastSetFromBigInteger(BigInteger bigInteger,
FastHiveDecimal fastResult)
Creates a fast decimal from a BigInteger with scale 0.
|
static boolean |
fastSetFromBigInteger(BigInteger bigInteger,
int scale,
FastHiveDecimal fastResult)
Creates a fast decimal from a BigInteger with a specified scale.
|
static boolean |
fastSetFromBigInteger(BigInteger bigInteger,
int scale,
int precision,
FastHiveDecimal fastResult)
Creates a fast decimal from a BigInteger with a specified scale.
|
static boolean |
fastSetFromBigIntegerBytesAndScale(byte[] bytes,
int offset,
int length,
int scale,
FastHiveDecimal fastResult)
Convert bytes in the format used by BigInteger's toByteArray format (and accepted by its
constructor) into a decimal using the specified scale.
|
static boolean |
fastSetFromBytes(byte[] bytes,
int offset,
int length,
boolean trimBlanks,
FastHiveDecimal fastResult)
Scan a byte array slice for a decimal number in UTF-8 bytes.
|
static boolean |
fastSetFromDigitsOnlyBytesAndScale(boolean isNegative,
byte[] bytes,
int offset,
int length,
int scale,
FastHiveDecimal fastResult)
Scans a byte array slice for UNSIGNED RAW DIGITS ONLY in UTF-8 (ASCII) characters and forms a
decimal from the digits and a sign and scale.
|
static boolean |
fastSetFromDouble(double doubleValue,
FastHiveDecimal fastResult)
Creates fast decimal from a double.
|
static boolean |
fastSetFromFloat(float floatValue,
FastHiveDecimal fastResult)
Creates fast decimal from a float.
|
static void |
fastSetFromInt(int intValue,
FastHiveDecimal fastResult)
Creates a scale 0 fast decimal from an int.
|
static void |
fastSetFromLong(long longValue,
FastHiveDecimal fastResult)
Creates a scale 0 fast decimal from a long.
|
static boolean |
fastSetFromLongAndScale(long longValue,
int scale,
FastHiveDecimal fastResult)
Creates a fast decimal from a long with a specified scale.
|
static boolean |
fastSetFromString(String string,
boolean trimBlanks,
FastHiveDecimal result)
Scan a String for a decimal number in UTF-8 characters.
|
static short |
fastShortValueClip(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale) |
static int |
fastSqlPrecision(FastHiveDecimal fastDec) |
static int |
fastSqlPrecision(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale) |
static boolean |
fastSubtract(FastHiveDecimal fastLeft,
FastHiveDecimal fastRight,
FastHiveDecimal fastResult) |
static boolean |
fastSubtract(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftIntegerDigitCount,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightIntegerDigitCount,
int rightScale,
FastHiveDecimal fastResult) |
static int |
fastToBytes(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int fastTrailingZeroesScale,
byte[] scratchBuffer) |
static int |
fastToDigitsOnlyBytes(long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
byte[] scratchBuffer) |
static String |
fastToDigitsOnlyString(long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount) |
static int |
fastToFormatBytes(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int formatScale,
byte[] scratchBuffer) |
static String |
fastToFormatString(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int formatScale) |
static String |
fastToFormatString(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int formatScale,
byte[] scratchBuffer) |
static String |
fastToString(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int fastTrailingZeroesScale) |
static String |
fastToString(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int fastTrailingZeroesScale,
byte[] scratchBuffer) |
static int |
fastTrailingDecimalZeroCount(long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale) |
static boolean |
fastUpdatePrecisionScale(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int maxPrecision,
int maxScale,
FastHiveDecimal.FastCheckPrecisionScaleStatus status,
FastHiveDecimal fastResult) |
static long |
getDecimal64AbsMax(int precision) |
static String |
getStackTraceAsSingleLine(StackTraceElement[] stackTrace) |
static boolean |
isAllZeroesBelow(int fastSignum,
long fast0,
long fast1,
long fast2,
int power) |
fastAbs, fastAdd, fastBigDecimalValue, fastBigIntegerBytes, fastBigIntegerBytesScaled, fastBigIntegerValue, fastByteValueClip, fastCheckPrecisionScale, fastCompareTo, fastCompareTo, fastDeserialize64, fastDivide, fastDoubleValue, fastEnforcePrecisionScale, fastEquals, fastFloatValue, fastFractionPortion, fastHashCode, fastIntegerDigitCount, fastIntegerPortion, fastIntValueClip, fastIsByte, fastIsInt, fastIsLong, fastIsShort, fastIsValid, fastLongValueClip, fastMultiply, fastNegate, fastNewFasterHashCode, fastPow, fastRaiseInvalidException, fastRaiseInvalidException, fastRawPrecision, fastRemainder, fastReset, fastRound, fastRoundingModeToString, fastScale, fastScaleByPowerOfTen, fastSerializationScale, fastSerializationUtilsRead, fastSerializationUtilsWrite, fastSerialize64, fastSet, fastSet, fastSetFromBigDecimal, fastSetFromBigInteger, fastSetFromBigIntegerAndScale, fastSetFromBigIntegerBytesAndScale, fastSetFromBytes, fastSetFromDigitsOnlyBytesAndScale, fastSetFromDouble, fastSetFromFloat, fastSetFromInt, fastSetFromLong, fastSetFromLongAndScale, fastSetFromString, fastSetSerializationScale, fastShortValueClip, fastSignum, fastSqlPrecision, fastSubtract, fastToBytes, fastToDigitsOnlyBytes, fastToDigitsOnlyString, fastToFormatBytes, fastToFormatString, fastToFormatString, fastToString, fastToString, fastUpdatePrecisionScale, isAllZeroesBelow, toStringpublic static final int MAX_DECIMAL_DIGITS
public static final int DECIMAL64_DECIMAL_DIGITS
public static final long MAX_ABS_DECIMAL64
public static final BigInteger BIG_INTEGER_MAX_DECIMAL
public static boolean fastSetFromBytes(byte[] bytes,
int offset,
int length,
boolean trimBlanks,
FastHiveDecimal fastResult)
Syntax: [+|-][integerPortion][.[fractionalDigits]][{E|e}[+|-]exponent] // Where at least one integer or fractional // digit is required...
We handle too many fractional digits by doing rounding ROUND_HALF_UP.
NOTE: The fastSetFromBytes method requires the caller to pass a fastResult parameter has been reset for better performance.
bytes - the bytes to copy fromoffset - the starting location in byteslength - the number of bytes to use from bytestrimBlanks - should spaces be trimmed?fastResult - True if the byte array slice was successfully converted to a decimal.public static boolean fastSetFromDigitsOnlyBytesAndScale(boolean isNegative,
byte[] bytes,
int offset,
int length,
int scale,
FastHiveDecimal fastResult)
Designed for BinarySortable serialization format that separates the sign and scale from the raw digits.
NOTE: The fastSetFromDigitsOnlyBytesAndScale method requires the caller to pass a fastResult parameter has been reset for better performance.
isNegative - is the number negativebytes - the bytes to read fromoffset - the position to start atlength - the number of bytes to readscale - the scale of the numberfastResult - an object it intopublic static boolean fastSetFromBigDecimal(BigDecimal bigDecimal, boolean allowRounding, FastHiveDecimal fastResult)
NOTE: The fastSetFromBigDecimal method requires the caller to pass a fastResult parameter has been reset for better performance.
bigDecimal - the big decimal to copyallowRounding - is rounding allowed?fastResult - an object to reusepublic static boolean fastSetFromString(String string, boolean trimBlanks, FastHiveDecimal result)
NOTE: The fastSetFromString method requires the caller to pass a fastResult parameter has been reset for better performance.
string - the string to parsetrimBlanks - should the blanks be trimmedresult - an object to reusepublic static void fastSetFromInt(int intValue,
FastHiveDecimal fastResult)
NOTE: The fastSetFromString method requires the caller to pass a fastResult parameter has been reset for better performance.
intValue - the value to setfastResult - an object to reusepublic static void fastSetFromLong(long longValue,
FastHiveDecimal fastResult)
NOTE: The fastSetFromLong method requires the caller to pass a fastResult parameter has been reset for better performance.
longValue - the value to setfastResult - an object to reusepublic static boolean fastSetFromLongAndScale(long longValue,
int scale,
FastHiveDecimal fastResult)
NOTE: The fastSetFromLongAndScale method requires the caller to pass a fastResult parameter has been reset for better performance.
longValue - the value to set as a longscale - the scale to usefastResult - an object to reusepublic static boolean fastSetFromFloat(float floatValue,
FastHiveDecimal fastResult)
NOTE: The fastSetFromFloat method requires the caller to pass a fastResult parameter has been reset for better performance.
floatValue - the value to setfastResult - an object to reusepublic static boolean fastSetFromDouble(double doubleValue,
FastHiveDecimal fastResult)
NOTE: The fastSetFromDouble method requires the caller to pass a fastResult parameter has been reset for better performance.
doubleValue - the value to setfastResult - an object to reusepublic static boolean fastSetFromBigInteger(BigInteger bigInteger, FastHiveDecimal fastResult)
For efficiency, we assume that fastResult is fastReset. This method does not set the fastScale field.
NOTE: The fastSetFromBigInteger method requires the caller to pass a fastResult parameter has been reset for better performance.
bigInteger - the value to setfastResult - an object to reusepublic static boolean fastSetFromBigInteger(BigInteger bigInteger, int scale, FastHiveDecimal fastResult)
NOTE: The fastSetFromBigInteger method requires the caller to pass a fastResult parameter has been reset for better performance.
bigInteger - the value to set as an integerscale - the scale to usefastResult - an object to reusepublic static boolean fastSetFromBigInteger(BigInteger bigInteger, int scale, int precision, FastHiveDecimal fastResult)
NOTE: The fastSetFromBigInteger method requires the caller to pass a fastResult parameter has been reset for better performance.
bigInteger - the value to set as an integerscale - the scale to useprecision - the precision to usefastResult - an object to reusepublic static void fastFractionPortion(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastScale,
FastHiveDecimal fastResult)
NOTE: The fastFractionPortion method requires the caller to pass a fastResult parameter has been reset for better performance.
fastSignum - the sign of the number (1, 0, or -1)fast0 - high bitsfast1 - second word bitsfast2 - third word bitsfastScale - the scalefastResult - an object to reusepublic static void fastIntegerPortion(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
FastHiveDecimal fastResult)
NOTE: The fastFractionPortion method requires the caller to pass a fastResult parameter has been reset for better performance.
fastSignum - the sign of the number (1, 0, or -1)fast0 - high bitsfast1 - second word bitsfast2 - third word bitsfastIntegerDigitCount - the number of integer digitsfastScale - the scalefastResult - an object to reusepublic static boolean doBinaryToDecimalConversion(long lowerWord,
long middleWord,
long highWord,
FastHiveDecimal middleWordMultiplier,
FastHiveDecimal highWordMultiplier,
FastHiveDecimal fastResult)
The 3 binary words highWord, middleWord, and lowerWord form a large binary value:
highWord * 2^(M+L) + middleWord * 2^L + lowerWord.
Where L is the number of bits in the lower word; M is the number of bits in the middle word. We let L and M be different to support the SerializationUtil serialization where the lower word is 62 bits and the remaining words are 63 bits...
lowerWord - the lower internal representationmiddleWord - the middle internal representationhighWord - the high internal representationmiddleWordMultiplier - 2^LhighWordMultiplier - 2^(M+L)fastResult - an object to reusepublic static boolean doDecimalToBinaryDivisionRemainder(long dividendFast0,
long dividendFast1,
long dividendFast2,
FastHiveDecimal fastInverseConst,
int quotientIntegerWordNum,
int quotientIntegerDigitNum,
FastHiveDecimal fastMultiplierConst,
long[] scratchLongs)
The fast decimal is longwords of 16 digits each and we need binary words of 2^N. Since we are in decimal form, we have do work to get to convert to binary form.
We effectively need to produce on big binary value (i.e. greater than 64 bits since HiveDecimal needs 128 bits of binary which Java does not provide primitive support for) from the decimal long words and get the lower N binary bit remainder.
We could try and do decimal division by 2^N to get the (integer) quotient, multiply the quotient by 2^N decimal, and finally do a decimal subtract that from the original decimal. The resulting decimal can be used to easily get the binary remainder.
However, currently, we do not have fast decimal division.
The "trick" we do here is to remember from your Algebra in school than multiplication and division are inverses of each other.
So instead of doing decimal division by 2^N we multiply by the inverse: 2^-N.
We produce 1 binary word (remainder) and a decimal quotient for the higher portion.
dividendFast0 - The input decimal that will produce a single binary word remainder and
decimal quotient.dividendFast1 - second worddividendFast2 - third wordfastInverseConst - the fast decimal inverse of 2^N = 2^-NquotientIntegerWordNum - the word in the inverse multiplication result to find the
quotient integer decimal portionquotientIntegerDigitNum - the digit in the result to find the quotient integer decimal
portionfastMultiplierConst - The fast decimal multiplier for converting the quotient integer to
the larger number to subtract from the input decimal to get the remainder.scratchLongs - where to store the result remainder word (index 3) and result quotient
decimal longwords (indices 0 .. 2)public static boolean fastSerializationUtilsRead(InputStream inputStream, int scale, byte[] scratchBytes, FastHiveDecimal fastResult) throws IOException
ORC uses those SerializationUtils methods for its serialization.
A scratch bytes array is necessary to do the binary to decimal conversion for better performance. Pass a FAST_SCRATCH_BUFFER_LEN_SERIALIZATION_UTILS_READ byte array for scratchBytes.
inputStream - the stream to read fromscale - the scale of the numberscratchBytes - An array for the binary to decimal conversion for better performance. Must
have length of FAST_SCRATCH_BUFFER_LEN_SERIALIZATION_UTILS_READ.fastResult - an object to reuseIOException - failures in reading the streampublic static boolean fastSerializationUtilsWrite(OutputStream outputStream, int fastSignum, long fast0, long fast1, long fast2, int fastIntegerDigitCount, int fastScale, long[] scratchLongs) throws IOException
Write the arbitrarily sized signed BigInteger in vint format.
Signed integers are encoded using the low bit as the sign bit using zigzag encoding.
Each byte uses the low 7 bits for data and the high bit for stop/continue.
Bytes are stored LSB first.
NOTE: SerializationUtils.writeBigInteger sometimes pads the result with extra zeroes due to BigInteger.bitLength -- we do not emulate that. SerializationUtils.readBigInteger will produce the same result for both.
outputStream - the stream to write tofastSignum - the sign digit (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1 of the internal representationfast2 - word 2 of the internal representationfastIntegerDigitCount - unusedfastScale - unusedscratchLongs - scratch spaceIOException - for problems in writingpublic static long getDecimal64AbsMax(int precision)
public static void fastDeserialize64(long inputDecimal64Long,
int inputScale,
FastHiveDecimal fastResult)
public static long fastSerialize64(int scale,
int fastSignum,
long fast1,
long fast0,
int fastScale)
public static boolean fastSetFromBigIntegerBytesAndScale(byte[] bytes,
int offset,
int length,
int scale,
FastHiveDecimal fastResult)
Our bigIntegerBytes methods create bytes in this format, too.
This method is designed for high performance and does not create an actual BigInteger during binary to decimal conversion.
bytes - the bytes to read fromoffset - the starting position in the bytes arraylength - the number of bytes to read from the bytes arrayscale - the scale of the numberfastResult - an object to reusedpublic static int fastBigIntegerBytes(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int fastSerializeScale,
long[] scratchLongs,
byte[] buffer)
public static int fastBigIntegerBytesUnscaled(int fastSignum,
long fast0,
long fast1,
long fast2,
long[] scratchLongs,
byte[] buffer)
Used by LazyBinary, Avro, and Parquet serialization.
Scratch objects necessary to do the decimal to binary conversion without actually creating a BigInteger object are passed for better performance.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2scratchLongs - scratch array of SCRATCH_LONGS_LEN longsbuffer - scratch array of SCRATCH_BUFFER_LEN_BIG_INTEGER_BYTES bytespublic static int fastBigIntegerBytesScaled(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int serializeScale,
long[] scratchLongs,
byte[] buffer)
Used by Avro and Parquet serialization.
This emulates the OldHiveDecimal setScale / OldHiveDecimal getInternalStorage() behavior.
fastSignum - the sign number (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scaleserializeScale - the scale to serializescratchLongs - a scratch array of longsbuffer - the buffer to serialize intopublic static boolean fastIsByte(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
Emulates testing for no value corruption: bigDecimalValue().setScale(0).equals(BigDecimal.valueOf(bigDecimalValue().byteValue()))
NOTE: Fractional digits are ignored in the test since fastByteValueClip() will remove them (round down).
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scale of the numberpublic static byte fastByteValueClip(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
public static boolean fastIsShort(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
Emulates testing for no value corruption: bigDecimalValue().setScale(0).equals(BigDecimal.valueOf(bigDecimalValue().shortValue()))
NOTE: Fractional digits are ignored in the test since fastShortValueClip() will remove them (round down).
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scale of the numberpublic static short fastShortValueClip(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
public static boolean fastIsInt(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
Emulates testing for no value corruption: bigDecimalValue().setScale(0).equals(BigDecimal.valueOf(bigDecimalValue().intValue()))
NOTE: Fractional digits are ignored in the test since fastIntValueClip() will remove them (round down).
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scale of the numberpublic static int fastIntValueClip(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
public static boolean fastIsLong(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
Emulates testing for no value corruption: bigDecimalValue().setScale(0).equals(BigDecimal.valueOf(bigDecimalValue().longValue()))
NOTE: Fractional digits are ignored in the test since fastLongValueClip() will remove them (round down).
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scale of the numberpublic static long fastLongValueClip(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
public static float fastFloatValue(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
public static double fastDoubleValue(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
public static BigInteger fastBigIntegerValue(int fastSignum, long fast0, long fast1, long fast2, int fastIntegerDigitCount, int fastScale, int fastSerializationScale)
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scale of the numberfastSerializationScale - the scale to serializepublic static BigInteger fastBigIntegerValueUnscaled(int fastSignum, long fast0, long fast1, long fast2)
public static BigInteger fastBigIntegerValueScaled(int fastSignum, long fast0, long fast1, long fast2, int fastIntegerDigitCount, int fastScale, int fastSerializationScale)
public static BigDecimal fastBigDecimalValue(int fastSignum, long fast0, long fast1, long fast2, int fastIntegerDigitCount, int fastScale)
NOTE: We are not representing our decimal as BigDecimal now as OldHiveDecimal did, so this is now slower.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scale of the numberpublic static int fastCompareTo(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftScale,
FastHiveDecimal fastRight)
public static int fastCompareTo(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightScale)
public static boolean fastEquals(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftScale,
FastHiveDecimal fastRight)
public static boolean fastEquals(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightScale)
public static int fastNewFasterHashCode(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
Faster than fastHashCode().
Used by map join and other Hive internal purposes where performance is important.
IMPORTANT: See comments for fastHashCode(), too.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scale of the numberpublic static int fastHashCode(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
We need this when the OldHiveDecimal hash code has been exposed and and written or affected how data is written.
This method supports compatibility.
Examples: bucketing and the Hive hash() function.
NOTE: It is necessary to create a BigDecimal object and use its hash code, so this method is slow.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scale of the numberpublic static boolean fastScaleByPowerOfTen(FastHiveDecimal fastDec, int power, FastHiveDecimal fastResult)
public static boolean fastScaleByPowerOfTen(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int power,
FastHiveDecimal fastResult)
public static boolean doFastRound(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int roundPower,
int roundingMode,
FastHiveDecimal fastResult)
public static boolean fastRound(FastHiveDecimal fastDec, int newScale, int roundingMode, FastHiveDecimal fastResult)
public static boolean fastRound(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int newScale,
int roundingMode,
FastHiveDecimal fastResult)
public static boolean fastRoundIntegerUp(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int roundPower,
FastHiveDecimal fastResult)
ceiling(12400.8302, -2) = 12500 // E.g. Positive case FAST_ROUND_CEILING rr rrrr
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scale of the numberroundPower - the power to round tofastResult - an object to reusepublic static boolean fastRoundIntegerDown(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int roundPower,
FastHiveDecimal fastResult)
The fraction being scaled away is thrown away.
The signum will be updated if the result is 0, otherwise the original sign is unchanged.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scale of the numberroundPower - the power to round tofastResult - an object to reusepublic static boolean fastRoundIntegerHalfUp(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int roundPower,
FastHiveDecimal fastResult)
When the fraction being scaled away is >= 0.5, the add 1.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scale of the numberroundPower - the power to round tofastResult - an object to reusepublic static boolean fastRoundIntegerHalfEven(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int roundPower,
FastHiveDecimal fastResult)
When the fraction being scaled away is exactly 0.5, then round and add 1 only if aaa. When fraction is not exactly 0.5, then if fraction > 0.5 then add 1. Otherwise, throw away fraction.
The signum will be updated if the result is 0, otherwise the original sign is unchanged.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fastIntegerDigitCount - the number of integer digitsfastScale - the scale of the numberroundPower - the power to round tofastResult - an object to reusepublic static boolean fastScaleDownNoRound(int fastSignum,
long fast0,
long fast1,
long fast2,
int scaleDown,
FastHiveDecimal fastResult)
When the fraction being scaled away is non-zero, return false.
The signum will be updated if the result is 0, otherwise the original sign is unchanged.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2scaleDown - the digits to scale down byfastResult - an object to reusepublic static boolean fastRoundFractionalUp(int fastSignum,
long fast0,
long fast1,
long fast2,
int scaleDown,
FastHiveDecimal fastResult)
When the fraction being scaled away is non-zero, the add 1.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2scaleDown - the number of integer digits to scalefastResult - an object to reusepublic static void fastRoundFractionalDown(int fastSignum,
long fast0,
long fast1,
long fast2,
int scaleDown,
FastHiveDecimal fastResult)
The fraction being scaled away is thrown away.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2scaleDown - the number of integer digits to scalefastResult - an object to reusepublic static boolean fastRoundFractionalHalfUp(int fastSignum,
long fast0,
long fast1,
long fast2,
int scaleDown,
FastHiveDecimal fastResult)
When the fraction being scaled away is >= 0.5, the add 1.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2scaleDown - the number of integer digits to scalefastResult - an object to reusepublic static boolean fastRoundFractionalHalfUp5Words(int fastSignum,
long fast0,
long fast1,
long fast2,
long fast3,
long fast4,
int scaleDown,
FastHiveDecimal fastResult)
When the fraction being scaled away is >= 0.5, the add 1.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2fast3 - word 3fast4 - word 4scaleDown - the number of integer digits to scalefastResult - an object to reusepublic static boolean fastRoundFractionalHalfEven(int fastSignum,
long fast0,
long fast1,
long fast2,
int scaleDown,
FastHiveDecimal fastResult)
When the fraction being scaled away is exactly 0.5, then round and add 1 only if aaa. When fraction is not exactly 0.5, then if fraction > 0.5 then add 1. Otherwise, throw away fraction.
fastSignum - the sign (-1, 0, or +1)fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2scaleDown - the number of integer digits to scalefastResult - an object to reusepublic static void doFastScaleDown(FastHiveDecimal fastDec, int scaleDown, FastHiveDecimal fastResult)
public static void doFastScaleDown(long fast0,
long fast1,
long fast2,
int scaleDown,
FastHiveDecimal fastResult)
The signum will be updated if the result is 0, otherwise the original sign is unchanged.
fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2scaleDown - the number of integer digits to scalefastResult - an object to reusepublic static boolean fastScaleUp(FastHiveDecimal fastDec, int scaleUp, FastHiveDecimal fastResult)
public static boolean fastScaleUp(long fast0,
long fast1,
long fast2,
int scaleUp,
FastHiveDecimal fastResult)
fast0 - word 0 of the internal representationfast1 - word 1fast2 - word 2scaleUp - the number of integer digits to scale up byfastResult - an object to reusepublic static int fastLongWordTrailingZeroCount(long longWord)
public static int fastHighWordTrailingZeroCount(long longWord)
public static int fastLongWordPrecision(long longWord)
public static int fastHighWordPrecision(long longWord)
public static int fastSqlPrecision(FastHiveDecimal fastDec)
public static int fastSqlPrecision(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
public static int fastRawPrecision(FastHiveDecimal fastDec)
public static int fastRawPrecision(int fastSignum,
long fast0,
long fast1,
long fast2)
public static boolean isAllZeroesBelow(int fastSignum,
long fast0,
long fast1,
long fast2,
int power)
public static boolean fastExceedsPrecision(long fast0,
long fast1,
long fast2,
int precision)
public static int fastTrailingDecimalZeroCount(long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
public static FastHiveDecimal.FastCheckPrecisionScaleStatus fastCheckPrecisionScale(int fastSignum, long fast0, long fast1, long fast2, int fastIntegerDigitCount, int fastScale, int maxPrecision, int maxScale)
public static boolean fastUpdatePrecisionScale(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int maxPrecision,
int maxScale,
FastHiveDecimal.FastCheckPrecisionScaleStatus status,
FastHiveDecimal fastResult)
public static boolean doAddSameScaleSameSign(FastHiveDecimal fastLeft, FastHiveDecimal fastRight, FastHiveDecimal fastResult)
public static boolean doAddSameScaleSameSign(int resultSignum,
long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
FastHiveDecimal fastResult)
public static boolean doSubtractSameScaleNoUnderflow(int resultSignum,
FastHiveDecimal fastLeft,
FastHiveDecimal fastRight,
FastHiveDecimal fastResult)
public static boolean doSubtractSameScaleNoUnderflow(int resultSignum,
long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
FastHiveDecimal fastResult)
public static boolean doSubtractSameScaleNoUnderflow(long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
long[] result)
public static boolean fastAdd(FastHiveDecimal fastLeft, FastHiveDecimal fastRight, FastHiveDecimal fastResult)
public static boolean fastAdd(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftIntegerDigitCount,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightIntegerDigitCount,
int rightScale,
FastHiveDecimal fastResult)
NOTE: Scale Determination for Addition/Subtraction
One could take the Math.min of the scales and adjust the operand with the lower scale have a scale = higher scale.
But this does not seem to work with decimals with widely varying scales as these:
598575157855521918987423259.94094 dec1 (int digits 27,scale 5) + 0.0000000000006711991169422033 dec2 (int digits 0, scale 28)
Trying to make dec1 to have a scale of 28 (i.e. by adding trailing zeroes) would exceed MAX_PRECISION (int digits 27 + 28 > 38).
In this example we need to make sure we have enough integer digit room in the result to handle dec1's digits. In order to maintain that, we will need to get rid of lower fractional digits of dec2. But when do we do that?
OldHiveDecimal.add does the full arithmetic add with all the digits using BigDecimal and then adjusts the result to fit in MAX_PRECISION, etc.
If we try to do pre-rounding dec2 it is problematic. We'd need to know if there is a carry in the arithmetic in order to know at which scale to do the rounding. This gets complicated.
So, the simplest thing is to emulate what OldHiveDecimal does and do the full digit addition and then fit the result afterwards.
leftSignum - The left sign (-1, 0, or +1)leftFast0 - The left word 0 of reprentationleftFast1 - word 1leftFast2 - word 2leftIntegerDigitCount - The left number of integer digitsleftScale - the left scalerightSignum - The right sign (-1, 0, or +1)rightFast0 - The right word 0 of reprentationrightFast1 - word 1rightFast2 - word 2rightIntegerDigitCount - The right number of integer digitsrightScale - the right scalefastResult - an object to reusepublic static boolean fastSubtract(FastHiveDecimal fastLeft, FastHiveDecimal fastRight, FastHiveDecimal fastResult)
public static boolean fastSubtract(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftIntegerDigitCount,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightIntegerDigitCount,
int rightScale,
FastHiveDecimal fastResult)
public static boolean fastMultiply5x5HalfWords(FastHiveDecimal fastLeft, FastHiveDecimal fastRight, FastHiveDecimal fastResult)
public static boolean fastMultiply5x5HalfWords(long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
FastHiveDecimal fastResult)
The caller is responsible checking for overflow within the highword and determining if scale down appropriate.
public static boolean fastMultiplyFullInternal(FastHiveDecimal fastLeft, FastHiveDecimal fastRight, long[] result)
public static boolean fastMultiply5x5HalfWords(long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
long[] result)
The caller is responsible checking for overflow within the highword and determining if scale down appropriate.
public static boolean fastMultiplyFullInternal(long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
long[] result)
The caller is responsible for determining the signum.
left0 - left1 - left2 - right0 - right1 - right2 - result - This full result has 5 longs.public static boolean fastMultiply5x6HalfWords(long left0,
long left1,
long left2,
long right0,
long right1,
long right2,
long[] result)
The caller is responsible for determining the signum.
result - This full result has 5 longs.public static boolean fastMultiply(FastHiveDecimal fastLeft, FastHiveDecimal fastRight, FastHiveDecimal fastResult)
public static boolean fastMultiply(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftIntegerDigitCount,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightIntegerDigitCount,
int rightScale,
FastHiveDecimal fastResult)
public static boolean fastDivide(FastHiveDecimal fastLeft, FastHiveDecimal fastRight, FastHiveDecimal fastResult)
public static boolean fastDivide(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftIntegerDigitCount,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightIntegerDigitCount,
int rightScale,
FastHiveDecimal fastResult)
public static boolean fastRemainder(int leftSignum,
long leftFast0,
long leftFast1,
long leftFast2,
int leftIntegerDigitCount,
int leftScale,
int rightSignum,
long rightFast0,
long rightFast1,
long rightFast2,
int rightIntegerDigitCount,
int rightScale,
FastHiveDecimal fastResult)
public static boolean fastPow(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int exponent,
FastHiveDecimal fastResult)
public static String fastToFormatString(int fastSignum, long fast0, long fast1, long fast2, int fastIntegerDigitCount, int fastScale, int formatScale)
public static String fastToFormatString(int fastSignum, long fast0, long fast1, long fast2, int fastIntegerDigitCount, int fastScale, int formatScale, byte[] scratchBuffer)
public static int fastToFormatBytes(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int formatScale,
byte[] scratchBuffer)
public static int doFastToFormatBytes(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int formatScale,
byte[] scratchBuffer)
public static String fastToString(int fastSignum, long fast0, long fast1, long fast2, int fastIntegerDigitCount, int fastScale, int fastTrailingZeroesScale)
public static String fastToString(int fastSignum, long fast0, long fast1, long fast2, int fastIntegerDigitCount, int fastScale, int fastTrailingZeroesScale, byte[] scratchBuffer)
public static String fastToDigitsOnlyString(long fast0, long fast1, long fast2, int fastIntegerDigitCount)
public static int fastToBytes(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale,
int fastTrailingZeroesScale,
byte[] scratchBuffer)
public static int fastToDigitsOnlyBytes(long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
byte[] scratchBuffer)
public static boolean fastIsValid(FastHiveDecimal fastDec)
public static boolean fastIsValid(int fastSignum,
long fast0,
long fast1,
long fast2,
int fastIntegerDigitCount,
int fastScale)
public static void fastRaiseInvalidException(FastHiveDecimal fastResult)
public static void fastRaiseInvalidException(FastHiveDecimal fastResult, String parameters)
public static String getStackTraceAsSingleLine(StackTraceElement[] stackTrace)
public static String displayBytes(byte[] bytes, int start, int length)
Copyright © 2023 The Apache Software Foundation. All rights reserved.