cpp/src/gandiva/precompiled/decimal_ops.cc
// Modify the scale and round.
Modify the scale and round.
Modify the scale and round .
static BasicDecimal128 RoundWithPositiveScale(const BasicDecimalScalar128& x,
                                              int32_t out_precision, int32_t out_scale,
                                              RoundType round_type, bool* overflow) {
  DCHECK_GE(out_scale, 0);
  auto scaled = ModifyScaleAndPrecision(x, out_precision, out_scale, overflow);
  if (*overflow) {
    return 0;
  }
  auto delta = ComputeRoundingDelta(x.value(), x.scale(), out_scale, round_type);
  if (delta == 0) {
    return scaled;
  }
  DCHECK_GT(x.scale(), out_scale);
  auto result = scaled + delta;
  DECIMAL_OVERFLOW_IF(out_precision < x.precision() &&
                          BasicDecimal128::Abs(result) > GetMaxValue(out_precision),
                      overflow);
  return result;
}
static BasicDecimal128 RoundWithPositiveScale ( const BasicDecimalScalar128 & x , int32_t out_precision , int32_t out_scale , RoundType round_type , bool * overflow ) { DCHECK_GE ( out_scale , 0 ) ; auto scaled = ModifyScaleAndPrecision ( x , out_precision , out_scale , overflow ) ; if ( * overflow ) { return 0 ; } auto delta = ComputeRoundingDelta ( x . value ( ) , x . scale ( ) , out_scale , round_type ) ; if ( delta == 0 ) { return scaled ; } DCHECK_GT ( x . scale ( ) , out_scale ) ; auto result = scaled + delta ; DECIMAL_OVERFLOW_IF ( out_precision < x . precision ( ) && BasicDecimal128 :: Abs ( result ) > GetMaxValue ( out_precision ) , overflow ) ; return result ; }
Modify the scale and round.
Modify the scale and round .
// If there is a rounding delta, the output scale must be less than the input scale. // That means at least one digit is dropped after the decimal. The delta add can add // utmost one digit before the decimal. So, overflow will occur only if the output // precision has changed.