IntShiftRight
Description
Shift an integer right by the given number of bit positions.
Parameters
| Name | Direction | Description |
|---|---|---|
value |
in | Integer to modify |
positions |
in | Number of low bits to discard |
Usage example (from documentation)
IntShiftRight(&value, 1);Success
Returns true. *value has been shifted in place.
Failure
Returns false on allocator OOM while trimming the significand. *value is left untouched.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:1131:
}
bool IntShiftRight(Int *value, u64 positions) {
ValidateInt(value);- In
Int.c:2063:
int cmp = 0;
if (!int_add(&sum, &low, &high) || !IntShiftRight(&sum, 1)) {
IntDeinit(&sum);
IntDeinit(&mid);- In
Int.c:2269:
u64 n_mod_8 = 0;
if (!IntShiftRight(&aa, 1)) {
IntDeinit(&aa);
IntDeinit(&nn);- In
Int.c:2596:
}
if (!IntShiftRight(&exp, 1)) {
IntDeinit(&acc);
IntDeinit(&base_mod);- In
Int.c:2812:
Int root = IntInit(IntAllocator(result));
if (!IntTryClone(&exponent, modulus) || !int_add_u64(&exponent, &exponent, 1) || !IntShiftRight(&exponent, 2) ||
!int_pow_mod(&root, &a, &exponent, modulus)) {
IntDeinit(&exponent);- In
Int.c:2846:
}
while (IntIsEven(&q)) {
if (!IntShiftRight(&q, 1)) {
IntDeinit(&q);
IntDeinit(&z);- In
Int.c:2900:
}
if (!IntTryClone(&exponent, &q) || !int_add_u64(&exponent, &exponent, 1) || !IntShiftRight(&exponent, 1) ||
!int_pow_mod(&r, &a, &exponent, modulus)) {
IntDeinit(&q);- In
Int.c:3119:
while (IntIsEven(&d)) {
if (!IntShiftRight(&d, 1)) {
IntDeinit(&d);
IntDeinit(&n_minus_one);- In
Math.c:90:
bool test_int_shift_right_shrinks(void) {
WriteFmt("Testing IntShiftRight\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:96:
Int value = IntFromBinary("110000", &alloc.base);
IntShiftRight(&value, 4);
bool result = IntToU64(&value) == 3;- In
Access.c:271:
// Replacing the call with a constant scalar (false/0) is observable.
bool test_m23_shift_right_zero_is_noop_true(void) {
WriteFmt("Testing IntShiftRight by zero positions\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Access.c:277:
Int value = IntFrom(5, &alloc.base);
bool ok = IntShiftRight(&value, 0);
bool result = ok && (IntToU64(&value) == 5);
Last updated on