Created
October 23, 2015 11:16
-
-
Save losipiuk/e2de3789edf0151f6a4c to your computer and use it in GitHub Desktop.
decimal operators builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final ParametricFunction DECIMAL_ADD_OPERATOR = decimalAddOperator(); | |
private static ParametricFunction decimalAddOperator() | |
{ | |
Signature signature = Signature.builder() | |
.type(SCALAR) | |
.operatorType(ADD) | |
.argumentTypes("decimal(p, s)", "decimal(p, s)") | |
.returnType("decimal(min(38, p + 1), s)") | |
.build(); | |
return ParametricFunction.builder(DecimalOperators.class) | |
.signature(signature) | |
.methods("addShortShortShort", "addLongLongLong", "addShortShortLong") | |
.build(); | |
} | |
public static long addShortShortShort(long a, long b) | |
{ | |
return a + b; | |
} | |
public static Slice addShortShortLong(long a, long b) | |
{ | |
BigInteger aBigInteger = BigInteger.valueOf(a); | |
BigInteger bBigInteger = BigInteger.valueOf(b); | |
BigInteger result = aBigInteger.add(bBigInteger); | |
return LongDecimalType.unscaledValueToSlice(result); | |
} | |
public static Slice addLongLongLong(Slice a, Slice b) | |
{ | |
BigInteger aBigInteger = LongDecimalType.unscaledValueToBigInteger(a); | |
BigInteger bBigInteger = LongDecimalType.unscaledValueToBigInteger(b); | |
BigInteger result = aBigInteger.add(bBigInteger); | |
checkOverflow(result); | |
return LongDecimalType.unscaledValueToSlice(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment