MCPcopy Create free account
hub / github.com/apache/arrow / ModifyScaleAndPrecision

Function ModifyScaleAndPrecision

cpp/src/gandiva/precompiled/decimal_ops.cc:536–553  ·  view source on GitHub ↗

Helper function to modify the scale and/or precision of a decimal value.

Source from the content-addressed store, hash-verified

534
535// Helper function to modify the scale and/or precision of a decimal value.
536static BasicDecimal128 ModifyScaleAndPrecision(const BasicDecimalScalar128& x,
537 int32_t out_precision, int32_t out_scale,
538 bool* overflow) {
539 int32_t delta_scale = out_scale - x.scale();
540 if (delta_scale >= 0) {
541 // check if multiplying by delta_scale will cause an overflow.
542 DECIMAL_OVERFLOW_IF(
543 BasicDecimal128::Abs(x.value()) > GetMaxValue(out_precision - delta_scale),
544 overflow);
545 return x.value().IncreaseScaleBy(delta_scale);
546 } else {
547 // Do not do any rounding, that is handled by the caller.
548 auto result = x.value().ReduceScaleBy(-delta_scale, false);
549 DECIMAL_OVERFLOW_IF(BasicDecimal128::Abs(result) > GetMaxValue(out_precision),
550 overflow);
551 return result;
552 }
553}
554
555enum RoundType {
556 kRoundTypeCeil, // +1 if +ve and trailing value is > 0, else no rounding.

Callers 2

RoundWithPositiveScaleFunction · 0.85
RoundWithNegativeScaleFunction · 0.85

Calls 6

GetMaxValueFunction · 0.85
IncreaseScaleByMethod · 0.80
ReduceScaleByMethod · 0.80
AbsFunction · 0.50
scaleMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected