FastHiveDecimal fastTemp = new FastHiveDecimal(); if (!fastScaleUp( fast0, fast1, fast2, FastHiveDecimal fastTemp = new FastHiveDecimal(); if (!fastRound( fastSignum, fast0, fast1, fast2,
@HiveDecimalWritableVersionV2 public static int compareTo(HiveDecimal dec, HiveDecimalWritable writable) { if (dec == null || !writable.isSet()) { throw new RuntimeException("Invalid comparision operand(s)"); } return FastHiveDecimal.fastCompareTo(dec, writable); }
protected FastHiveDecimal() { fastReset(); }
public static boolean fastPow( int fastSignum, long fast0, long fast1, long fast2, int fastIntegerDigitCount, int fastScale, int exponent, FastHiveDecimal fastResult) { // Arithmetic operations (re)set the results. fastResult.fastSet(fastSignum, fast0, fast1, fast2, fastIntegerDigitCount, fastScale); if (exponent < 0) { // UNDONE: Currently, negative exponent is not supported. return false; } for (int e = 1; e < exponent; e++) { if (!doMultiply( fastResult.fastSignum, fastResult.fast0, fastResult.fast1, fastResult.fast2, fastResult.fastIntegerDigitCount, fastResult.fastScale, fastResult.fastSignum, fastResult.fast0, fastResult.fast1, fastResult.fast2, fastResult.fastIntegerDigitCount, fastResult.fastScale, fastResult)) { return false; } } return true; }
protected boolean fastSetFromString(String string, boolean trimBlanks) { byte[] bytes = string.getBytes(); return fastSetFromBytes( bytes, 0, bytes.length, trimBlanks); }
/** * When fastSetFromBigIntegerBytesAndScale can handle the input because it is too large, * we fall back to this. */ private static boolean doAlternateSetFromBigIntegerBytesAndScale( byte[] bytes, int offset, int length, int scale, FastHiveDecimal fastResult) { byte[] byteArray = Arrays.copyOfRange(bytes, offset, offset + length); BigInteger bigInteger = new BigInteger(byteArray); // System.out.println("doAlternateSetFromBigIntegerBytesAndScale bigInteger " + bigInteger); BigDecimal bigDecimal = new BigDecimal(bigInteger, scale); // System.out.println("doAlternateSetFromBigIntegerBytesAndScale bigDecimal " + bigDecimal); fastResult.fastReset(); return fastSetFromBigDecimal(bigDecimal, true, 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) { if (rightSignum == 0) { fastResult.fastSet(leftSignum, leftFast0, leftFast1, leftFast2, leftIntegerDigitCount, leftScale); return true; } final int flippedDecSignum = (rightSignum == 1 ? -1 : 1); if (leftSignum == 0) { fastResult.fastSet(flippedDecSignum, rightFast0, rightFast1, rightFast2, rightIntegerDigitCount, rightScale); return true; } if (leftScale == rightScale) { return doAddSameScale( leftSignum, leftFast0, leftFast1, leftFast2, flippedDecSignum, rightFast0, rightFast1, rightFast2, leftScale, fastResult); } else { return doAddDifferentScale( leftSignum, leftFast0, leftFast1, leftFast2, leftIntegerDigitCount, leftScale, flippedDecSignum, rightFast0, rightFast1, rightFast2, rightIntegerDigitCount, rightScale, fastResult); } }
protected boolean fastSetFromString(String string, boolean trimBlanks) { byte[] bytes = string.getBytes(); return fastSetFromBytes( bytes, 0, bytes.length, trimBlanks); }
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) { if (leftSignum == 0 || rightSignum == 0) { fastResult.fastReset(); return true; } return doMultiply( leftSignum, leftFast0, leftFast1, leftFast2, leftIntegerDigitCount, leftScale, rightSignum, rightFast0, rightFast1, rightFast2, rightIntegerDigitCount, rightScale, fastResult); }
public static int doFastToFormatBytes( int fastSignum, long fast0, long fast1, long fast2, int fastIntegerDigitCount, int fastScale, int formatScale, byte[] scratchBuffer) { // NOTE: OldHiveDecimal.toFormatString returns decimal strings with more than > 38 digits! if (formatScale >= fastScale) { return doFastToBytes( fastSignum, fast0, fast1, fast2, fastIntegerDigitCount, fastScale, formatScale, scratchBuffer); } else { FastHiveDecimal fastTemp = new FastHiveDecimal(); if (!fastRound( fastSignum, fast0, fast1, fast2, fastIntegerDigitCount, fastScale, formatScale, BigDecimal.ROUND_HALF_UP, fastTemp)) { return 0; } return doFastToBytes( fastTemp.fastSignum, fastTemp.fast0, fastTemp.fast1, fastTemp.fast2, fastTemp.fastIntegerDigitCount, fastTemp.fastScale, formatScale, scratchBuffer); } }
@HiveDecimalWritableVersionV2 public static int compareTo(HiveDecimal dec, HiveDecimalWritable writable) { if (dec == null || !writable.isSet()) { throw new RuntimeException("Invalid comparision operand(s)"); } return FastHiveDecimal.fastCompareTo(dec, writable); }
fastResult.fastReset(); } else { fastResult.fastSignum = fastSignum;
public static boolean fastPow( int fastSignum, long fast0, long fast1, long fast2, int fastIntegerDigitCount, int fastScale, int exponent, FastHiveDecimal fastResult) { // Arithmetic operations (re)set the results. fastResult.fastSet(fastSignum, fast0, fast1, fast2, fastIntegerDigitCount, fastScale); if (exponent < 0) { // UNDONE: Currently, negative exponent is not supported. return false; } for (int e = 1; e < exponent; e++) { if (!doMultiply( fastResult.fastSignum, fastResult.fast0, fastResult.fast1, fastResult.fast2, fastResult.fastIntegerDigitCount, fastResult.fastScale, fastResult.fastSignum, fastResult.fast0, fastResult.fast1, fastResult.fast2, fastResult.fastIntegerDigitCount, fastResult.fastScale, fastResult)) { return false; } } return true; }
new FastHiveDecimal(1, 1686018427387904L, 461L, 0, 19, 0); new FastHiveDecimal(1, 3372036854775808L, 922L, 0, 19, 0); new FastHiveDecimal(1, 1825928971026432L, 9586511730793292L, 425352L, 38, 0); new FastHiveDecimal(1, 6994171142578125L, 5044340074528008L, 1084202172485L, 45, 0); new FastHiveDecimal(1, 2057594037927936L, 7L, 0, 17, 0); new FastHiveDecimal(1, 8530496329220096L, 9229685853482762L, 51L, 34, 0); new FastHiveDecimal(1, 9585113525390625L, 8078144567552953L, 13877787L, 40, 0); new FastHiveDecimal((long) Byte.MIN_VALUE - 1L); private static final FastHiveDecimal FASTHIVEDECIMAL_MAX_BYTE_VALUE_PLUS_ONE = new FastHiveDecimal((long) Byte.MAX_VALUE + 1L); new FastHiveDecimal((long) Short.MIN_VALUE - 1L); private static final FastHiveDecimal FASTHIVEDECIMAL_MAX_SHORT_VALUE_PLUS_ONE = new FastHiveDecimal((long) Short.MAX_VALUE + 1L); new FastHiveDecimal((long) Integer.MIN_VALUE - 1L); private static final FastHiveDecimal FASTHIVEDECIMAL_MAX_INT_VALUE_PLUS_ONE = new FastHiveDecimal((long) Integer.MAX_VALUE + 1L); new FastHiveDecimal(Long.MIN_VALUE); private static final FastHiveDecimal FASTHIVEDECIMAL_MAX_LONG_VALUE = new FastHiveDecimal(Long.MAX_VALUE);
public static void fastDeserialize64( final long inputDecimal64Long, final int inputScale, FastHiveDecimal fastResult) { long decimal64Long; if (inputDecimal64Long == 0) { fastResult.fastReset(); return; } else if (inputDecimal64Long > 0) { fastResult.fastSignum = 1; decimal64Long = inputDecimal64Long; } else { fastResult.fastSignum = -1; decimal64Long = -inputDecimal64Long; } // Trim trailing zeroes -- but only below the decimal point. int trimScale = inputScale; while (trimScale > 0 && decimal64Long % 10 == 0) { decimal64Long /= 10; trimScale--; } fastResult.fast2 = 0; fastResult.fast1 = decimal64Long / MULTIPLER_LONGWORD_DECIMAL; fastResult.fast0 = decimal64Long % MULTIPLER_LONGWORD_DECIMAL; fastResult.fastScale = trimScale; fastResult.fastIntegerDigitCount = Math.max(0, fastRawPrecision(fastResult) - fastResult.fastScale); }