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:254:
static bool int_is_one(const Int *value) {
ValidateInt(value);
return IntBitLength(value) == 1 && BitVecGet(INT_BITS(value), 0);
}- In
Int.c:390:
}
u64 IntBitLength(const Int *value) {
return int_significant_bits(value);
}- In
Int.c:395:
u64 IntByteLength(const Int *value) {
u64 bits = IntBitLength(value);
return bits == 0 ? 0 : CEIL_DIV(bits, 8u);
}- In
Int.c:411:
}
*out = IntBitLength(value) - 1;
return true;
}- In
Int.c:439:
bool IntIsZero(const Int *value) {
return IntBitLength(value) == 0;
}- In
Int.c:457:
bool IntFitsU64(const Int *value) {
ValidateInt(value);
return IntBitLength(value) <= 64;
}- In
Int.c:463:
ValidateInt(value);
return !IntIsZero(value) && IntBitLength(value) == IntTrailingZeroCount(value) + 1;
}- In
Int.c:792:
Int remainder = IntInit(alloc);
if (!int_try_from_u64(&chunk_divisor, chunk, alloc) || !IntReserve("ient, IntBitLength(value))) {
IntDeinit(&chunk_divisor);
IntDeinit("ient);- In
Int.c:1012:
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:1029:
ValidateInt(b);
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);- In
Int.c:1030:
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);
if (a_bits != b_bits) {- In
Int.c:1063:
ValidateInt(lhs);
if (IntBitLength(lhs) > 64) {
return 1;
}- In
Int.c:1094:
ValidateInt(value);
u64 bits = IntBitLength(value);
if (positions == 0) {- In
Int.c:1134:
ValidateInt(value);
u64 bits = IntBitLength(value);
if (positions == 0) {- In
Int.c:1270:
ValidateInt(b);
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);
u64 max_bits = MAX2(a_bits, b_bits);- In
Int.c:1271:
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);
u64 max_bits = MAX2(a_bits, b_bits);- In
Int.c:1365:
}
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);- In
Int.c:1366:
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);
if (!BitVecResize(INT_BITS(result), a_bits)) {- In
Int.c:1450:
{
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);
u64 a_words = (a_bits + 63u) / 64u;- In
Int.c:1451:
{
u64 a_bits = IntBitLength(a);
u64 b_bits = IntBitLength(b);
u64 a_words = (a_bits + 63u) / 64u;
u64 b_words = (b_bits + 63u) / 64u;- In
Int.c:1656:
{
u64 dividend_bits = IntBitLength(dividend);
u64 divisor_bits = IntBitLength(divisor);
u64 r_words = (divisor_bits + 1u + 63u) / 64u;- In
Int.c:1657:
{
u64 dividend_bits = IntBitLength(dividend);
u64 divisor_bits = IntBitLength(divisor);
u64 r_words = (divisor_bits + 1u + 63u) / 64u;- In
Int.c:2027:
}
u64 bits = IntBitLength(value);
u64 high_shift = bits / degree;
Int low = IntInit(IntAllocator(root));- In
Int.c:2209:
ValidateInt(value);
if (IntIsZero(value) || IntBitLength(value) == 1) {
return true;
}- In
Compare.c:207:
Int lhs = IntFrom(0x8000000000000000u, &alloc.base);
bool fail = (IntBitLength(&lhs) != 64); // sanity: exactly 64 bits.
fail = fail || (IntCompare(&lhs, 0x8000000000000000u) != 0);- In
Type.c:24:
bool result = IntIsZero(&value);
result = result && (IntBitLength(&value) == 0);
IntDeinit(&value);- In
Type.c:41:
bool result = IntIsZero(&value);
result = result && (IntBitLength(&value) == 0);
IntDeinit(&value);- In
Type.c:126:
bool result = (IntToU64(&sum) == 256);
result = result && (IntBitLength(&sum) == 9);
IntDeinit(&a);- In
Type.c:148:
Int v255 = IntFrom(255, &alloc.base);
bool result = IntBitLength(&v255) == 8;
result = result && (IntToU64(&v255) == 255);- In
Math.c:82:
bool result = IntToU64(&value) == 48;
result = result && (IntBitLength(&value) == 6);
IntDeinit(&value);- In
Math.c:99:
bool result = IntToU64(&value) == 3;
result = result && (IntBitLength(&value) == 2);
IntDeinit(&value);- In
Math.c:1570:
bool result = ok && IntIsZero(&product);
result = result && (IntToU64(&product) == 0u);
result = result && (IntBitLength(&product) == 0u);
IntDeinit(&a);- In
Math.c:2259:
bool fail = (IntCompare(&value, 5u) != 0);
fail = fail || (IntBitLength(&value) != 3);
IntDeinit(&value);- In
Math.c:2277:
bool fail = (IntCompare(&value, 1u) != 0);
fail = fail || (IntBitLength(&value) != 1);
IntDeinit(&value);- In
Convert.c:101:
Str text = IntToBinary(&value);
bool result = IntBitLength(&value) == 4;
result = result && (IntToU64(&value) == 13);
result = result && (ZstrCompare(StrBegin(&text), "1101") == 0);- In
Convert.c:273:
bool error = true;
bool result = IntBitLength(&zero) == 0;
result = result && IntIsZero(&zero);
result = result && (IntToU64(&zero, &error) == 0);- In
Convert.c:293:
bool result = IntToU64(&value) == 163;
result = result && (IntBitLength(&value) == 8);
IntDeinit(&value);- In
Convert.c:624:
bool result = ok && (IntToU64(&product) == (u64)273u);
/* 273 = 0b100010001, 9 significant bits */
result = result && (IntBitLength(&product) == 9);
IntDeinit(&a);- In
Convert.c:1439:
bool result = (IntToU64(&value) == 5);
result = result && (IntBitLength(&value) == 3);
IntDeinit(&value);- In
Access.c:28:
bool test_int_bit_length(void) {
WriteFmt("Testing IntBitLength\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Access.c:34:
Int value = IntFromBinary("00101000", &alloc.base);
bool result = IntBitLength(&value) == 6;
IntDeinit(&value);- In
Access.c:321:
Int value = IntFrom((u64)40u, &alloc.base);
bool result = (IntBitLength(&value) == 6u);
result = result && (IntTrailingZeroCount(&value) == 3u);- In
Access.c:338:
///
static bool test_m28_bit_length_invalid_deadend(void) {
WriteFmt("Testing IntBitLength validation on invalid Int\n");
Int invalid = {0};- In
Access.c:342:
Int invalid = {0};
(void)IntBitLength(&invalid);
return false;
Last updated on