cpp/src/gandiva/precompiled/decimal_ops.cc
// Helper function to modify the scale and/or precision of a decimal value.
Helper function to modify the scale and/or precision of a decimal value.
Helper function to modify the scale and / or precision of a decimal value .
static BasicDecimal128 ModifyScaleAndPrecision(const BasicDecimalScalar128& x,
                                               int32_t out_precision, int32_t out_scale,
                                               bool* overflow) {
  int32_t delta_scale = out_scale - x.scale();
  if (delta_scale >= 0) {
    DECIMAL_OVERFLOW_IF(
        BasicDecimal128::Abs(x.value()) > GetMaxValue(out_precision - delta_scale),
        overflow);
    return x.value().IncreaseScaleBy(delta_scale);
  } else {
    auto result = x.value().ReduceScaleBy(-delta_scale, false);
    DECIMAL_OVERFLOW_IF(BasicDecimal128::Abs(result) > GetMaxValue(out_precision),
                        overflow);
    return result;
  }
}
static BasicDecimal128 ModifyScaleAndPrecision ( const BasicDecimalScalar128 & x , int32_t out_precision , int32_t out_scale , bool * overflow ) { int32_t delta_scale = out_scale - x . scale ( ) ; if ( delta_scale >= 0 ) { DECIMAL_OVERFLOW_IF ( BasicDecimal128 :: Abs ( x . value ( ) ) > GetMaxValue ( out_precision - delta_scale ) , overflow ) ; return x . value ( ) . IncreaseScaleBy ( delta_scale ) ; } else { auto result = x . value ( ) . ReduceScaleBy ( - delta_scale , false ) ; DECIMAL_OVERFLOW_IF ( BasicDecimal128 :: Abs ( result ) > GetMaxValue ( out_precision ) , overflow ) ; return result ; } }
Helper function to modify the scale and/or precision of a decimal value.
Helper function to modify the scale and / or precision of a decimal value .
// check if multiplying by delta_scale will cause an overflow. // Do not do any rounding, that is handled by the caller.