MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / shl_bits

Method shl_bits

Source/external/fast_float.h:2301–2324  ·  view source on GitHub ↗

shift left each limb n bits, carrying over to the new limb returns true if we were able to shift all the digits.

Source from the content-addressed store, hash-verified

2299 // shift left each limb n bits, carrying over to the new limb
2300 // returns true if we were able to shift all the digits.
2301 FASTFLOAT_CONSTEXPR20 bool shl_bits(size_t n) noexcept {
2302 // Internally, for each item, we shift left by n, and add the previous
2303 // right shifted limb-bits.
2304 // For example, we transform (for u8) shifted left 2, to:
2305 // b10100100 b01000010
2306 // b10 b10010001 b00001000
2307 FASTFLOAT_DEBUG_ASSERT(n != 0);
2308 FASTFLOAT_DEBUG_ASSERT(n < sizeof(limb) * 8);
2309
2310 size_t shl = n;
2311 size_t shr = limb_bits - shl;
2312 limb prev = 0;
2313 for (size_t index = 0; index < vec.len(); index++) {
2314 limb xi = vec[index];
2315 vec[index] = (xi << shl) | (prev >> shr);
2316 prev = xi;
2317 }
2318
2319 limb carry = prev >> shr;
2320 if (carry != 0) {
2321 return vec.try_push(carry);
2322 }
2323 return true;
2324 }
2325
2326 // move the limbs left by `n` limbs.
2327 FASTFLOAT_CONSTEXPR20 bool shl_limbs(size_t n) noexcept {

Callers

nothing calls this directly

Calls 2

try_pushMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected