IntShiftLeft
Description
Shift an integer left by the given number of bit positions.
Parameters
| Name | Direction | Description |
|---|---|---|
value |
in | Integer to modify |
positions |
in | Number of zero bits to append on the right |
Usage example (from documentation)
IntShiftLeft(&value, 8);Success
Returns true. *value has been shifted in place.
Failure
Returns false on allocator OOM while growing the significand. *value is left untouched.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:599:
for (u64 i = 0; i < len; i++) {
if (!IntShiftLeft(&result, 8) || !int_add_u64_in_place(&result, bytes[i])) {
IntDeinit(&result);
return IntInit(alloc);- In
Int.c:1091:
}
bool IntShiftLeft(Int *value, u64 positions) {
ValidateInt(value);- In
Int.c:2049:
}
if (!IntShiftLeft(&high, high_shift)) {
IntDeinit(&low);
IntDeinit(&high);- In
Float.c:71:
if (binexp > 0) {
if (!IntShiftLeft(&out->significand, (u64)binexp)) {
return false;
}- In
Compare.c:75:
Int big = IntFrom(1, &alloc.base);
IntShiftLeft(&big, 80);
bool result = (IntCompare(&value, &same) == 0);- In
Compare.c:130:
Int small = IntFrom(42u, &alloc.base);
Int large = IntFrom(1u, &alloc.base);
IntShiftLeft(&large, 80);
Int decimal = IntFromStr("12345678901234567890", &alloc.base);- In
Type.c:59:
result = result && (IntToU64(&clone) == 11);
IntShiftLeft(&original, 1);
result = result && !IntEQ(&clone, &original);- In
Math.c:73:
bool test_int_shift_left_grows(void) {
WriteFmt("Testing IntShiftLeft\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:79:
Int value = IntFrom(3, &alloc.base);
IntShiftLeft(&value, 4);
bool result = IntToU64(&value) == 48;- In
Math.c:973:
bool test_int_shift_left_null(void) {
WriteFmt("Testing IntShiftLeft NULL handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:977:
DefaultAllocator alloc = DefaultAllocatorInit();
IntShiftLeft(NULL, 1);
DefaultAllocatorDeinit(&alloc);
return false;- In
Math.c:2933:
Int value = IntFrom(1, &alloc.base);
IntShiftLeft(&value, 50); // 2^50
Int root = IntInit(&alloc.base);- In
Convert.c:433:
bool error = false;
IntShiftLeft(&value, 64);
bool result = !IntTryToU64(&value, &out);- In
Access.c:116:
Int big = IntFrom(1, &alloc.base);
IntShiftLeft(&big, 64);
bool result = IntFitsU64(&small);- In
Access.c:170:
Int zero = IntInit(&alloc.base);
IntShiftLeft(&power, 20);
bool result = IntIsPowerOfTwo(&one);- In
Access.c:294:
// ---------------------------------------------------------------------------
bool test_m24_shift_left_zero_noop(void) {
WriteFmt("Testing IntShiftLeft(&v, 0) returns true, value unchanged\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Access.c:299:
Int value = IntFrom(7u, &alloc.base);
bool ok = IntShiftLeft(&value, 0);
bool fail = !ok; // must report success.
Last updated on