MCPcopy Index your code
hub / github.com/pquerna/ffjson / leftShift

Function leftShift

fflib/v1/decimal.go:232–275  ·  view source on GitHub ↗

Binary shift left (/ 2) by k bits. k <= maxShift to avoid overflow.

(a *decimal, k uint)

Source from the content-addressed store, hash-verified

230
231// Binary shift left (/ 2) by k bits. k <= maxShift to avoid overflow.
232func leftShift(a *decimal, k uint) {
233 delta := leftcheats[k].delta
234 if prefixIsLessThan(a.d[0:a.nd], leftcheats[k].cutoff) {
235 delta--
236 }
237
238 r := a.nd // read index
239 w := a.nd + delta // write index
240 n := 0
241
242 // Pick up a digit, put down a digit.
243 for r--; r >= 0; r-- {
244 n += (int(a.d[r]) - '0') << k
245 quo := n / 10
246 rem := n - 10*quo
247 w--
248 if w < len(a.d) {
249 a.d[w] = byte(rem + '0')
250 } else if rem != 0 {
251 a.trunc = true
252 }
253 n = quo
254 }
255
256 // Put down extra digits.
257 for n > 0 {
258 quo := n / 10
259 rem := n - 10*quo
260 w--
261 if w < len(a.d) {
262 a.d[w] = byte(rem + '0')
263 } else if rem != 0 {
264 a.trunc = true
265 }
266 n = quo
267 }
268
269 a.nd += delta
270 if a.nd >= len(a.d) {
271 a.nd = len(a.d)
272 }
273 a.dp += delta
274 trim(a)
275}
276
277// Binary shift left (k > 0) or right (k < 0).
278func (a *decimal) Shift(k int) {

Callers 1

ShiftMethod · 0.70

Calls 2

prefixIsLessThanFunction · 0.70
trimFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…