MCPcopy Create free account
hub / github.com/apache/impala / MaxBitsRequiredIncreaseAfterScaling

Function MaxBitsRequiredIncreaseAfterScaling

be/src/runtime/decimal-value.inline.h:157–173  ·  view source on GitHub ↗

Suppose we have a number that requires x bits to be represented and we scale it up by 10^scale_by. Let's say now y bits are required to represent it. This function returns the maximum possible y - x for a given 'scale_by'.

Source from the content-addressed store, hash-verified

155// 10^scale_by. Let's say now y bits are required to represent it. This function returns
156// the maximum possible y - x for a given 'scale_by'.
157inline int MaxBitsRequiredIncreaseAfterScaling(int scale_by) {
158 // We rely on the following formula:
159 // bits_required(x * 10^y) <= bits_required(x) + floor(log2(10^y)) + 1
160 // We precompute floor(log2(10^x)) + 1 for x = 0, 1, 2...75, 76
161 DCHECK_GE(scale_by, 0);
162 DCHECK_LE(scale_by, 76);
163 static const int floor_log2_plus_one[] = {
164 0, 4, 7, 10, 14, 17, 20, 24, 27, 30,
165 34, 37, 40, 44, 47, 50, 54, 57, 60, 64,
166 67, 70, 74, 77, 80, 84, 87, 90, 94, 97,
167 100, 103, 107, 110, 113, 117, 120, 123, 127, 130,
168 133, 137, 140, 143, 147, 150, 153, 157, 160, 163,
169 167, 170, 173, 177, 180, 183, 187, 190, 193, 196,
170 200, 203, 206, 210, 213, 216, 220, 223, 226, 230,
171 233, 236, 240, 243, 246, 250, 253 };
172 return floor_log2_plus_one[scale_by];
173}
174
175// If we have a number with 'num_lz' leading zeros, and we scale it up by 10^scale_by,
176// this function returns the minimum number of leading zeros the result can have.

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected