Returns the maximum possible number of bits required to represent num * 10^scale_by.
| 183 | |
| 184 | // Returns the maximum possible number of bits required to represent num * 10^scale_by. |
| 185 | inline int MaxBitsRequiredAfterScaling(int128_t num, int scale_by) { |
| 186 | // TODO: We are doing a lot of these abs() operations on int128_t in many places in our |
| 187 | // decimal math code. It might make sense to do this upfront, then do the calculations |
| 188 | // in unsigned math and adjust the sign at the end. |
| 189 | int num_occupied = 128 - BitUtil::CountLeadingZeros<int128_t>(abs(num)); |
| 190 | DCHECK_GE(scale_by, 0); |
| 191 | DCHECK_LE(scale_by, 76); |
| 192 | return num_occupied + MaxBitsRequiredIncreaseAfterScaling(scale_by); |
| 193 | } |
| 194 | |
| 195 | // Returns the minimum number of leading zero x or y would have after one of them gets |
| 196 | // scaled up to match the scale of the other one. |