bignum

Arbitrary Precision Integers

Constants

BN_BASE = 1000000000

Functions

FunctionDescription
_bn_allocInternal: allocate BigNum with given limb capacity.
bn_newCreate BigNum from i64 value.
bn_from_strParse decimal string to BigNum. Handles optional leading ‘-’.
bn_abs_cmpCompare magnitudes (ignoring sign). Returns -1, 0, or 1.
bn_cmpCompare two BigNums. Returns -1, 0, or 1.
_bn_add_magInternal: add magnitudes. Both must be non-negative limb arrays.
_bn_sub_magInternal: subtract magnitudes.
bn_addAdd two BigNums.
bn_subSubtract: a - b.
bn_mulMultiply two BigNums. Grade-school algorithm.
bn_is_zeroCheck if BigNum is zero.
bn_negateNegate: return new BigNum with flipped sign.
bn_to_strConvert BigNum to decimal string. Returns length written.
bn_to_i64Convert BigNum to i64 (truncates if too large).

Details

_bn_alloc

fn _bn_alloc(cap: i64) -> &i64

Internal: allocate BigNum with given limb capacity.

bn_new

fn bn_new(val: i64) -> &i64

Create BigNum from i64 value.

bn_from_str

fn bn_from_str(s: &i8, slen: i64) -> &i64

Parse decimal string to BigNum. Handles optional leading ‘-’.

bn_abs_cmp

fn bn_abs_cmp(a: &i64, b: &i64) -> i64

Compare magnitudes (ignoring sign). Returns -1, 0, or 1.

bn_cmp

fn bn_cmp(a: &i64, b: &i64) -> i64

Compare two BigNums. Returns -1, 0, or 1.

_bn_add_mag

fn _bn_add_mag(a: &i64, b: &i64) -> &i64

Internal: add magnitudes. Both must be non-negative limb arrays.

_bn_sub_mag

fn _bn_sub_mag(a: &i64, b: &i64) -> &i64

Internal: subtract magnitudes. |a| must be >= |b|.

bn_add

fn bn_add(a: &i64, b: &i64) -> &i64

Add two BigNums.

bn_sub

fn bn_sub(a: &i64, b: &i64) -> &i64

Subtract: a - b.

bn_mul

fn bn_mul(a: &i64, b: &i64) -> &i64

Multiply two BigNums. Grade-school algorithm.

bn_is_zero

fn bn_is_zero(a: &i64) -> i64

Check if BigNum is zero.

bn_negate

fn bn_negate(a: &i64) -> &i64

Negate: return new BigNum with flipped sign.

bn_to_str

fn bn_to_str(a: &i64, out: &i8) -> i64

Convert BigNum to decimal string. Returns length written.

bn_to_i64

fn bn_to_i64(a: &i64) -> i64

Convert BigNum to i64 (truncates if too large).