cpp/src/gandiva/precompiled/decimal_ops.cc
// Compute the rounding delta for the givven rounding type.
Compute the rounding delta for the givven rounding type.
Compute the rounding delta for the givven rounding type .
static int32_t ComputeRoundingDelta(const BasicDecimal128& x, int32_t x_scale,
                                    int32_t out_scale, RoundType type) {
  if (type == kRoundTypeTrunc ||  
      out_scale >= x_scale) {     
    return 0;
  }
  int32_t result = 0;
  switch (type) {
    case kRoundTypeHalfRoundUp: {
      auto base = BasicDecimal128::GetScaleMultiplier(x_scale - out_scale);
      auto trailing = x % base;
      if (trailing == 0) {
        result = 0;
      } else if (trailing.Abs() < base / 2) {
        result = 0;
      } else {
        result = (x < 0) ? -1 : 1;
      }
      break;
    }
    case kRoundTypeCeil:
      if (x < 0) {
        result = 0;
      } else {
        auto base = BasicDecimal128::GetScaleMultiplier(x_scale - out_scale);
        auto trailing = x % base;
        result = (trailing == 0) ? 0 : 1;
      }
      break;
    case kRoundTypeFloor:
      if (x > 0) {
        result = 0;
      } else {
        auto base = BasicDecimal128::GetScaleMultiplier(x_scale - out_scale);
        auto trailing = x % base;
        result = (trailing == 0) ? 0 : -1;
      }
      break;
    case kRoundTypeTrunc:
      break;
  }
  return result;
}
static int32_t ComputeRoundingDelta ( const BasicDecimal128 & x , int32_t x_scale , int32_t out_scale , RoundType type ) { if ( type == kRoundTypeTrunc || out_scale >= x_scale ) { return 0 ; } int32_t result = 0 ; switch ( type ) { case kRoundTypeHalfRoundUp : { auto base = BasicDecimal128 :: GetScaleMultiplier ( x_scale - out_scale ) ; auto trailing = x % base ; if ( trailing == 0 ) { result = 0 ; } else if ( trailing . Abs ( ) < base / 2 ) { result = 0 ; } else { result = ( x < 0 ) ? -1 : 1 ; } break ; } case kRoundTypeCeil : if ( x < 0 ) { result = 0 ; } else { auto base = BasicDecimal128 :: GetScaleMultiplier ( x_scale - out_scale ) ; auto trailing = x % base ; result = ( trailing == 0 ) ? 0 : 1 ; } break ; case kRoundTypeFloor : if ( x > 0 ) { result = 0 ; } else { auto base = BasicDecimal128 :: GetScaleMultiplier ( x_scale - out_scale ) ; auto trailing = x % base ; result = ( trailing == 0 ) ? 0 : -1 ; } break ; case kRoundTypeTrunc : break ; } return result ; }
Compute the rounding delta for the givven rounding type.
Compute the rounding delta for the givven rounding type .
// no rounding for this type. // no digits dropped, so no rounding. // no rounding for -ve // no rounding for +ve