big_int bi_from_str(string str [, int base])
converts string representation of number
str with base
base
to big_int resource. If
base is not set, function assumes that it is
equal to 10.
base can be from 2 to 36 inclusive.
Returns: converted to big_int resource number on success or NULL on error.
string bi_to_str(big_int num [, int base])
converts big_int number
num to string representation with
base
base. If
base is not set, function assumes that it is
equal to 10.
base can be from 2 to 36 inclusive.
Returns: converted to string big_int number
num or NULL on error.
string bi_base_convert(string str, int base_from, int base_to)
converts string representation of number
str with base
base_from
into string representation with base
base_to.
base_from and
base_to can be from 2 to 36 inclusive.
Returns: converted string or NULL on error.
string bi_serialize(big_int a [, bool is_sign])
serializes number
a to bytestream.
If
is_sign is TRUE, then serialize the sign of
a too.
Else it will not serialized.
Returns: serialized value of
a or NULL on error.
big_int bi_unserialize(string str [, bool is_sign])
unserializes number from bytestream
str.
If
is_sign is TRUE, then unserialize the sign of
a.
Else it will not unserialized.
Returns: unserialized number or NULL on error.
big_int bi_add(big_int a, big_int b)
calculates
a +
b.
Returns:
a +
b or NULL on error.
big_int bi_sub(big_int a, big_int b)
calculates
a -
b.
Returns:
a -
b or NULL on error.
big_int bi_mul(big_int a, big_int b)
calculates
a *
b.
Returns:
a *
b or NULL on error.
big_int bi_div(big_int a, big_int b)
calculates integer part of
a /
b.
Returns: integer part of
a /
b or NULL on error.
big_int bi_mod(big_int a, big_int b)
calculates
a %
b.
Returns:
a %
b or NULL on error.
big_int bi_muladd(big_int a, big_int b, big_int c)
calculates
c +
a *
b.
Returns:
c +
a *
b or NULL on error.
big_int bi_sqr(big_int num)
calculates square of
num.
Returns: sqr(
num) or NULL on error.
big_int bi_abs(big_int num)
calculates abs(
num).
Returns: abs(
num) or NULL on error.
big_int bi_neg(big_int num)
calculates -(
num).
Returns: -(
num) or NULL on error.
big_int bi_inc(big_int num)
calculates
num + 1.
Returns:
num + 1 or NULL on error.
big_int bi_dec(big_int num)
calculates
num - 1.
Returns:
num - 1 or NULL on error.
bool bi_is_zero(big_int num)
compares
num with zero.
Returns: TRUE, if
num equals to zero. FALSE otherwise or NULL on error.
bool bi_is_one(big_int num)
compares
num with 1.
Returns: TRUE, if
num equals to 1. FALSE otherwise or NULL on error.
int bi_sign(big_int num)
determines the sign of
num.
Returns:
1, if
num > 0
0, if
num = 0
-1, if
num < 0
or NULL on error.
int bi_cmp(big_int a, big_int b)
compares
a with
b.
Returns:
-1, if
a <
b
0, if
a =
b
1, if
a >
b
or NULL on error
int bi_cmp_abs(big_int a, big_int b)
compares abs(
a) with abs(
b).
Returns:
-1, if abs(
a) < abs(
b)
0, if abs(
a) = abs(
b)
1, if abs(
a) > abs(
b)
or NULL on error
big_int bi_or(big_int a, big_int b[, int start_pos])
calculates bitwise
a or
b, starting from
start_pos bit of number
a.
Returns:
a or
b or NULL on error.
big_int bi_and(big_int a, big_int b[, int start_pos])
calculates bitwise
a and
b, starting from
start_pos bit of number
a.
Returns:
a and
b or NULL on error.
big_int bi_xor(big_int a, big_int b[, int start_pos])
calculates bitwise
a xor
b, starting from
start_pos bit of number
a.
Returns:
a xor
b or NULL on error.
big_int bi_andnot(big_int a, big_int b[, int start_pos])
calculates bitwise
a and !
b, starting from
start_pos bit of number
a.
Returns:
a and !
b or NULL on error.
int bi_bit_len(big_int num)
counts bit length of
num.
Returns: bit length of
num or NULL on error.
int bi_bit1_cnt(big_int num)
counts 1-bits in the
num.
Returns: number of 1-bits in the
num or NULL on error.
big_int bi_lshift(big_int num, int bits_cnt)
shifts number
num by
bits_cnt bits to the left.
Returns: shifted number or NULL on error.
big_int bi_rshift(big_int num, int bits_cnt)
shifts number
num by
bits_cnt bits to the right.
Returns: shifted number or NULL on error.
big_int bi_set_bit(big_int num, int bit_pos)
sets bit number
bit_pos to the 1.
Returns:
num with bit number
bit_pos setted to 1 or NULL on error.
big_int bi_clr_bit(big_int num, int bit_pos)
clears bit number
bit_pos to the 0.
Returns:
num with bit number
bit_pos cleared to 0 or NULL on error.
big_int bi_inv_bit(big_int num, int bit_pos)
inverts bit number
bit_pos int the
num.
Returns:
num with inverted bit number
bit_pos or NULL on error.
int bi_test_bit(big_int num, int bit_pos)
determines value of bit number
bit_pos in the
num.
Returns: value of bit number
bit_pos in the
num or NULL on error.
int bi_scan0_bit(big_int num, int start_pos)
determines the position of the next 0-bit after bit number
start_pos in the
num.
Returns: founded next position of the 0-bit or NULL on error.
int bi_scan1_bit(big_int num, int start_pos)
determines the position of the next 1-bit after bit number
start_pos in the
num.
Returns: founded next position of the 1-bit or NULL on error.
int bi_hamming_distance(big_int a, big_int b)
calculates the Hamming distance between
a and
b.
Returns: calculated Hamming distance or NULL on error.
big_int bi_subint(big_int num, int start_pos, int len [, int is_invert])
cuts
len bits of the number
num starting from
start_pos bit.
If
is_invert is not 0, then invert cutted bits.
Returns: number, containing of cutted bits or NULL on error.
big_int bi_addmod(big_int a, big_int b, big_int modulus)
calculates
a +
b (mod
modulus).
Returns:
a +
b (mod
modulus) or NULL on error.
big_int bi_submod(big_int a, big_int b, big_int modulus)
calculates
a -
b (mod
modulus).
Returns:
a -
b (mod
modulus) or NULL on error.
big_int bi_mulmod(big_int a, big_int b, big_int modulus)
calculates
a *
b (mod
modulus).
Returns:
a *
b (mod
modulus) or NULL on error.
big_int bi_divmod(big_int a, big_int b, big_int modulus)
calculates
a /
b (mod
modulus).
Returns:
a /
b (mod
modulus) or NULL on error.
big_int bi_powmod(big_int a, big_int b, big_int modulus)
calculates pow(
a,
b) (mod
modulus).
Returns: pow(
a,
b) (mod
modulus) or NULL on error.
big_int bi_factmod(big_int num, big_int modulus)
calculates
num! (mod
modulus).
Returns:
num! (mod
modulus) or NULL on error.
big_int bi_absmod(big_int num, big_int modulus)
calculates
num (mod
modulus).
Returns:
num (mod
modulus) or NULL on error.
big_int bi_invmod(big_int num, big_int modulus)
calculates pow(
num, -1) (mod
modulus).
Returns: pow(
num, -1) (mod
modulus) or NULL on error.
big_int bi_sqrmod(big_int num, big_int modulus)
calculates sqr(
num) (mod
modulus).
Returns: sqr(
num) (mod
modulus) or NULL on error.
int bi_cmpmod(big_int a, big_int b, big_int modulus)
compares
a with
b by modulus
modulus.
Returns:
-1, if
a <
b (mod
modulus)
0, if
a =
b (mod
modulus)
1, if
a >
b (mod
modulus)
or NULL on error.
big_int bi_sqrt(big_int num)
calculates integer part of square root of
num.
Returns: sqrt(
num) or NULL on error.
big_int bi_sqr_rem(big_int num)
calculates remainder of square root of
num.
This is a number
x:
x =
num - sqr(int(sqrt(
num)))
Returns: remainder of square root of
num or NULL on error.
big_int bi_gcd(big_int a, big_int b)
calculates greatest common divider (GCD) of
a and
b.
Returns: GCD(
a,
b) or NULL on error.
array bi_gcd_extended(big_int a, big_int b)
Returns array(
0 => gcd(
a,
b),
1 => u,
2 => v,
);
Where abs(
a) * u + abs(
b) * v = gcd(
a,
b)
int bi_is_prime(big_int num)
Primality test of
num.
Returns:
0, if
num is composite
1, if
num is pseudoprime
2, if
num is proven prime
or NULL on error.
big_int bi_next_prime(big_int num)
finds next strong pseudoprime after
num.
Returns: next strong pseudoprime after
num or NULL on error.
array bi_div_extended(big_int a, big_int b)
calculates
q and
r, so
a =
q *
b +
r.
Returns: array(
q,
r) or NULL on error.
big_int bi_rand(int bits_cnt[, string rand_func_name])
generates equidistributed pseudorandom number with length
bits_cnt bits.
if
rand_func_name is set, then use it for generating random number,
else use rand() function from standard C library.
Note: this function uses only lower byte of value,
returned by user function named [function_name].
User function must return integer.
Returns: generated pseudorandom number or NULL on error.
int bi_miller_test(big_int a, big_int base)
Primality test of
a with help of base
base.
Returns:
0, if
a is composite
1, if
a is pseudoprime by base
base
or NULL on error.
int bi_jacobi(big_int a, big_int b)
calculates Jacobi symbol (
a|
b) .
Returns: Jacobi symbol or NULL on error.
big_int bi_fact(int a)
calculates factorial of
a.
Returns:
a! or NULL on error.
big_int bi_pow(big_int a, int b)
powers
a by power
b.
Returns: pow(
a,
b) or NULL on error.
array bi_info()
Returns associative array, containing information, related to big_int extension:
array(
'digit_size' => size of big_int word in bits,
'ext_version' => version of big_int extension,
'lib_version' => version of big_int library version,
'ext_build_date' => date of big_int extension building,
'lib_build_date' => date of big_int library building,
);