bignum
Arbitrary Precision Integers
Constants
BN_BASE = 1000000000Functions
| Function | Description |
|---|---|
_bn_alloc | Internal: allocate BigNum with given limb capacity. |
bn_new | Create BigNum from i64 value. |
bn_from_str | Parse decimal string to BigNum. Handles optional leading ‘-’. |
bn_abs_cmp | Compare magnitudes (ignoring sign). Returns -1, 0, or 1. |
bn_cmp | Compare two BigNums. Returns -1, 0, or 1. |
_bn_add_mag | Internal: add magnitudes. Both must be non-negative limb arrays. |
_bn_sub_mag | Internal: subtract magnitudes. |
bn_add | Add two BigNums. |
bn_sub | Subtract: a - b. |
bn_mul | Multiply two BigNums. Grade-school algorithm. |
bn_is_zero | Check if BigNum is zero. |
bn_negate | Negate: return new BigNum with flipped sign. |
bn_to_str | Convert BigNum to decimal string. Returns length written. |
bn_to_i64 | Convert BigNum to i64 (truncates if too large). |
Details
_bn_alloc
fn _bn_alloc(cap: i64) -> &i64Internal: allocate BigNum with given limb capacity.
bn_new
fn bn_new(val: i64) -> &i64Create BigNum from i64 value.
bn_from_str
fn bn_from_str(s: &i8, slen: i64) -> &i64Parse decimal string to BigNum. Handles optional leading ‘-’.
bn_abs_cmp
fn bn_abs_cmp(a: &i64, b: &i64) -> i64Compare magnitudes (ignoring sign). Returns -1, 0, or 1.
bn_cmp
fn bn_cmp(a: &i64, b: &i64) -> i64Compare two BigNums. Returns -1, 0, or 1.
_bn_add_mag
fn _bn_add_mag(a: &i64, b: &i64) -> &i64Internal: add magnitudes. Both must be non-negative limb arrays.
_bn_sub_mag
fn _bn_sub_mag(a: &i64, b: &i64) -> &i64Internal: subtract magnitudes. |a| must be >= |b|.
bn_add
fn bn_add(a: &i64, b: &i64) -> &i64Add two BigNums.
bn_sub
fn bn_sub(a: &i64, b: &i64) -> &i64Subtract: a - b.
bn_mul
fn bn_mul(a: &i64, b: &i64) -> &i64Multiply two BigNums. Grade-school algorithm.
bn_is_zero
fn bn_is_zero(a: &i64) -> i64Check if BigNum is zero.
bn_negate
fn bn_negate(a: &i64) -> &i64Negate: return new BigNum with flipped sign.
bn_to_str
fn bn_to_str(a: &i64, out: &i8) -> i64Convert BigNum to decimal string. Returns length written.
bn_to_i64
fn bn_to_i64(a: &i64) -> i64Convert BigNum to i64 (truncates if too large).