Helper function to modify the scale and/or precision of a decimal value.
| 534 | |
| 535 | // Helper function to modify the scale and/or precision of a decimal value. |
| 536 | static 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 | |
| 555 | enum RoundType { |
| 556 | kRoundTypeCeil, // +1 if +ve and trailing value is > 0, else no rounding. |
no test coverage detected