Skip to content

Add bit_length() API to BigInt and OwnedBigInt#603

Merged
reaperhulk merged 1 commit intomainfrom
claude/bigint-bit-count-api-9er35
Mar 8, 2026
Merged

Add bit_length() API to BigInt and OwnedBigInt#603
reaperhulk merged 1 commit intomainfrom
claude/bigint-bit-count-api-9er35

Conversation

@alex
Copy link
Owner

@alex alex commented Mar 1, 2026

Add a bit_length() method that returns the number of significant bits in the integer's magnitude (absolute value), matching the conventional semantics of Python's int.bit_length().

For non-negative values this strips the 0x00 sign byte and counts significant bits directly. For negative values the magnitude bit count is derived from the two's complement representation by computing bit_length(|x| - 1) and correcting when |x| is a power of two.

Tests are table-driven (i64, expected) pairs that round-trip through DER serialization.

https://claude.ai/code/session_01B2QqS4ek4j1fDskfSPdLUi

Add a bit_length() method that returns the number of significant
bits in the integer's magnitude (absolute value), matching the
conventional semantics of Python's int.bit_length().

For non-negative values this strips the 0x00 sign byte and counts
significant bits directly. For negative values the magnitude bit
count is derived from the two's complement representation by
computing bit_length(|x| - 1) and correcting when |x| is a power
of two.

Tests are table-driven (i64, expected) pairs that round-trip
through DER serialization.

https://claude.ai/code/session_01B2QqS4ek4j1fDskfSPdLUi
@alex alex force-pushed the claude/bigint-bit-count-api-9er35 branch from 258bf5f to 9dc5083 Compare March 1, 2026 19:40
@reaperhulk reaperhulk merged commit ae72c7a into main Mar 8, 2026
13 checks passed
@reaperhulk reaperhulk deleted the claude/bigint-bit-count-api-9er35 branch March 8, 2026 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants