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

Function RoundWithPositiveScale

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

Modify the scale and round.

Source from the content-addressed store, hash-verified

613
614// Modify the scale and round.
615static BasicDecimal128 RoundWithPositiveScale(const BasicDecimalScalar128& x,
616 int32_t out_precision, int32_t out_scale,
617 RoundType round_type, bool* overflow) {
618 DCHECK_GE(out_scale, 0);
619
620 auto scaled = ModifyScaleAndPrecision(x, out_precision, out_scale, overflow);
621 if (*overflow) {
622 return 0;
623 }
624
625 auto delta = ComputeRoundingDelta(x.value(), x.scale(), out_scale, round_type);
626 if (delta == 0) {
627 return scaled;
628 }
629
630 // If there is a rounding delta, the output scale must be less than the input scale.
631 // That means at least one digit is dropped after the decimal. The delta add can add
632 // utmost one digit before the decimal. So, overflow will occur only if the output
633 // precision has changed.
634 DCHECK_GT(x.scale(), out_scale);
635 auto result = scaled + delta;
636 DECIMAL_OVERFLOW_IF(out_precision < x.precision() &&
637 BasicDecimal128::Abs(result) > GetMaxValue(out_precision),
638 overflow);
639 return result;
640}
641
642// Modify scale to drop all digits to the right of the decimal and round.
643// Then, zero out 'rounding_scale' number of digits to the left of the decimal point.

Callers 6

RoundFunction · 0.85
TruncateFunction · 0.85
CeilFunction · 0.85
FloorFunction · 0.85
ConvertFunction · 0.85
ToInt64Function · 0.85

Calls 7

ModifyScaleAndPrecisionFunction · 0.85
ComputeRoundingDeltaFunction · 0.85
GetMaxValueFunction · 0.85
AbsFunction · 0.50
valueMethod · 0.45
scaleMethod · 0.45
precisionMethod · 0.45

Tested by

no test coverage detected