| 119 | } |
| 120 | |
| 121 | BasicDecimal32 BasicDecimal32::ReduceScaleBy(int32_t reduce_by, bool round) const { |
| 122 | DCHECK_GE(reduce_by, 0); |
| 123 | DCHECK_LE(reduce_by, kMaxScale); |
| 124 | |
| 125 | if (reduce_by == 0) { |
| 126 | return *this; |
| 127 | } |
| 128 | |
| 129 | BasicDecimal32 divisor(DecimalTraits<BasicDecimal32>::powers_of_ten()[reduce_by]); |
| 130 | BasicDecimal32 result; |
| 131 | BasicDecimal32 remainder; |
| 132 | auto s = Divide(divisor, &result, &remainder); |
| 133 | DCHECK_EQ(s, DecimalStatus::kSuccess); |
| 134 | if (round) { |
| 135 | auto divisor_half = DecimalTraits<BasicDecimal32>::half_powers_of_ten()[reduce_by]; |
| 136 | if (remainder.Abs() >= divisor_half) { |
| 137 | result += Sign(); |
| 138 | } |
| 139 | } |
| 140 | return result; |
| 141 | } |
| 142 | |
| 143 | const BasicDecimal32& BasicDecimal32::GetScaleMultiplier(int32_t scale) { |
| 144 | DCHECK_GE(scale, 0); |