16 #ifndef IMPALA_EXPRS_DECIMAL_OPERATORS_H
17 #define IMPALA_EXPRS_DECIMAL_OPERATORS_H
23 using namespace impala_udf;
57 static DecimalVal Subtract_DecimalVal_DecimalVal(
59 static DecimalVal Multiply_DecimalVal_DecimalVal(
61 static DecimalVal Divide_DecimalVal_DecimalVal(
102 const ColumnType& output_type,
const DecimalRoundOp& op);
123 const ColumnType& output_type,
const DecimalRoundOp& op, int64_t rounding_scale);
146 template <
typename T>
149 if (op == TRUNCATE)
return 0;
152 if (src_scale <= target_scale)
return 0;
156 if (v.
value() > 0 && op == FLOOR)
return 0;
157 if (v.
value() < 0 && op == CEIL)
return 0;
161 int delta_scale = src_scale - target_scale;
162 DCHECK_GT(delta_scale, 0);
165 T trailing_base = DecimalUtil::GetScaleMultiplier<T>(delta_scale);
166 T trailing_digits = v.
value() % trailing_base;
169 if (trailing_digits == 0)
return 0;
172 if (op == CEIL)
return 1;
173 if (op == FLOOR)
return -1;
175 DCHECK_EQ(op, ROUND);
177 if (
abs(trailing_digits) < trailing_base / 2)
return 0;
178 return v.
value() < 0 ? -1 : 1;
int128_t abs(const int128_t &x)
static T RoundDelta(const DecimalValue< T > &v, int src_scale, int target_scale, const DecimalRoundOp &op)
This object has a compatible storage format with boost::ptime.
Additional digits are dropped.