IntBitLength
Description
Number of significant bits required to represent the magnitude of an integer.
Parameters
| Name | Direction | Description |
|---|---|---|
value |
in | Integer to inspect. |
Success
Returns the bit length as a u64. Returns 0 when value is zero. The integer is not modified.
Failure
Function cannot fail. An invalid value pointer is a caller bug and aborts via LOG_FATAL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:229:
static bool int_is_one(const Int *value) {
ValidateInt(value);
return IntBitLength(value) == 1 && BitVecGet(INT_BITS(value), 0);
}- In
Int.c:365:
}
u64 IntBitLength(const Int *value) {
return int_significant_bits(value);
}- In
Int.c:370:
u64 IntByteLength(const Int *value) {
u64 bits = IntBitLength(value);
return bits == 0 ? 0 : CEIL_DIV(bits, 8u);
}- In
Int.c:386:
}
*out = IntBitLength(value) - 1;
return true;
}- In
Int.c:414:
bool IntIsZero(const Int *value) {
return IntBitLength(value) == 0;
}- In
Int.c:432:
bool IntFitsU64(const Int *value) {
ValidateInt(value);
return IntBitLength(value) <= 64;
}- In
Int.c:438:
ValidateInt(value);
return !IntIsZero(value) && IntBitLength(value) == IntTrailingZeroCount(value) + 1;
}- In
Int.c:933:
ValidateInt(value);
u64 bits = IntBitLength(value);
u64 bytes = bits == 0 ? 0 : CEIL_DIV(bits, 8u);
const u8 *magnitude = (const u8 *)BitVecData(INT_BITS(value));- In
Int.c:950:
ValidateInt(b);
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);- In
Int.c:951:
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);
if (a_bits < b_bits) {- In
Int.c:975:
ValidateInt(lhs);
if (IntBitLength(lhs) > 64) {
return 1;
}- In
Int.c:1006:
ValidateInt(value);
u64 bits = IntBitLength(value);
if (positions == 0) {- In
Int.c:1034:
ValidateInt(value);
u64 bits = IntBitLength(value);
if (positions == 0) {- In
Int.c:1060:
ValidateInt(b);
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);
u64 max_bits = MAX2(a_bits, b_bits);- In
Int.c:1061:
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);
u64 max_bits = MAX2(a_bits, b_bits);
Int temp;- In
Int.c:1143:
}
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);
Int temp;- In
Int.c:1144:
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);
Int temp;
bool borrow = false;- In
Int.c:1209:
ValidateInt(b);
u64 b_bits = IntBitLength(b);
Int acc = IntInit(IntAllocator(result));- In
Int.c:1375:
if (int_compare(&normalized_dividend, &normalized_divisor) >= 0) {
u64 dividend_bits = IntBitLength(&normalized_dividend);
u64 divisor_bits = IntBitLength(&normalized_divisor);- In
Int.c:1376:
if (int_compare(&normalized_dividend, &normalized_divisor) >= 0) {
u64 dividend_bits = IntBitLength(&normalized_dividend);
u64 divisor_bits = IntBitLength(&normalized_divisor);
IntDeinit(&q);- In
Int.c:1403:
r = next;
if (IntBitLength(&q) < bit + 1 && !BitVecResize(INT_BITS(&q), bit + 1)) {
IntDeinit(&shifted);
goto cleanup;- In
Int.c:1730:
}
u64 bits = IntBitLength(value);
u64 high_shift = bits / degree;
Int low = IntInit(IntAllocator(root));- In
Int.c:1912:
ValidateInt(value);
if (IntIsZero(value) || IntBitLength(value) == 1) {
return true;
}- In
Int.Access.c:20:
bool test_int_bit_length(void) {
WriteFmt("Testing IntBitLength\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Access.c:26:
Int value = IntFromBinary("00101000", &alloc.base);
bool result = IntBitLength(&value) == 6;
IntDeinit(&value);- In
Int.Convert.c:47:
Str text = IntToBinary(&value);
bool result = IntBitLength(&value) == 4;
result = result && (IntToU64(&value) == 13);
result = result && (ZstrCompare(StrBegin(&text), "1101") == 0); bool error = true;
bool result = IntBitLength(&zero) == 0;
result = result && IntIsZero(&zero);
result = result && (IntToU64(&zero, &error) == 0);
bool result = IntToU64(&value) == 163;
result = result && (IntBitLength(&value) == 8);
IntDeinit(&value);- In
Int.Type.c:22:
bool result = IntIsZero(&value);
result = result && (IntBitLength(&value) == 0);
IntDeinit(&value);- In
Int.Type.c:39:
bool result = IntIsZero(&value);
result = result && (IntBitLength(&value) == 0);
IntDeinit(&value);- In
Int.Math.c:72:
bool result = IntToU64(&value) == 48;
result = result && (IntBitLength(&value) == 6);
IntDeinit(&value);- In
Int.Math.c:89:
bool result = IntToU64(&value) == 3;
result = result && (IntBitLength(&value) == 2);
IntDeinit(&value);
Last updated on