divide input by 10^reduce_by, and round up the fractional part.
| 165 | |
| 166 | // divide input by 10^reduce_by, and round up the fractional part. |
| 167 | static int256_t ReduceScaleBy(int256_t in, int32_t reduce_by) { |
| 168 | if (reduce_by == 0) { |
| 169 | // nothing to do. |
| 170 | return in; |
| 171 | } |
| 172 | |
| 173 | int256_t divisor = GetScaleMultiplier(reduce_by); |
| 174 | DCHECK_GT(divisor, 0); |
| 175 | DCHECK_EQ(divisor % 2, 0); // multiple of 10. |
| 176 | auto result = in / divisor; |
| 177 | auto remainder = in % divisor; |
| 178 | // round up (same as BasicDecimal128::ReduceScaleBy) |
| 179 | if (abs(remainder) >= (divisor >> 1)) { |
| 180 | result += (in > 0 ? 1 : -1); |
| 181 | } |
| 182 | return result; |
| 183 | } |
| 184 | |
| 185 | // multiply input by 10^increase_by. |
| 186 | static int256_t IncreaseScaleBy(int256_t in, int32_t increase_by) { |
no test coverage detected