PostgreSQL Source Code
git master
|
Go to the source code of this file.
Macros | |
#define | assert(TEST) Assert(TEST) |
#define | MP_VALUE_DIGITS(V) ((sizeof(V) + (sizeof(mp_digit) - 1)) / sizeof(mp_digit)) |
#define | SWAP(T, A, B) |
#define | DECLARE_TEMP(N) |
#define | CLEANUP_TEMP() |
#define | TEMP(K) (temp_.value + (K)) |
#define | REQUIRE(E) |
Variables | |
const mp_result | MP_OK = 0 |
const mp_result | MP_FALSE = 0 |
const mp_result | MP_TRUE = -1 |
const mp_result | MP_MEMORY = -2 |
const mp_result | MP_RANGE = -3 |
const mp_result | MP_UNDEF = -4 |
const mp_result | MP_TRUNC = -5 |
const mp_result | MP_BADARG = -6 |
const mp_result | MP_MINERR = -6 |
const mp_sign | MP_NEG = 1 |
const mp_sign | MP_ZPOS = 0 |
static const char * | s_unknown_err = "unknown result code" |
static const char * | s_error_msg [] |
static const double | s_log2 [] |
static mp_size | default_precision = 8 |
static mp_size | multiply_threshold = 32 |
#define assert | ( | TEST | ) | Assert(TEST) |
Definition at line 73 of file imath.c.
Referenced by addchr(), addrange(), allocarc(), bracket(), breakconstraintloop(), brenext(), caltdissect(), cbracket(), cbrdissect(), cclass_column_index(), ccondissect(), cdissect(), cfind(), cfindloop(), changearctarget(), citerdissect(), cleanup(), clearcvec(), cloneouts(), clonesuccessorstates(), colorcomplement(), combine(), compact(), copyins(), copyouts(), createarc(), crevcondissect(), creviterdissect(), delsub(), deltraverse(), destroystate(), dumpnfa(), duptraverse(), eclass(), element(), find(), findconstraintloop(), fixconstraintloops(), fixempties(), freearc(), freecnfa(), freecolor(), freelacons(), freestate(), generate_unaccent_rules::get_plain_letter(), generate_unaccent_rules::get_plain_letters(), getladfa(), getvacant(), IncreaseBuffer(), inet_cidr_pton_ipv4(), inet_net_pton_ipv4(), initialize(), lacon(), lexescape(), lexnest(), lexstart(), makesearch(), markst(), matchuntil(), mergeins(), miss(), moresubs(), moveins(), moveouts(), mp_int_abs(), mp_int_add(), mp_int_compare(), mp_int_compare_unsigned(), mp_int_compare_uvalue(), mp_int_compare_value(), mp_int_compare_zero(), mp_int_copy(), mp_int_count_bits(), mp_int_default_precision(), mp_int_div(), mp_int_div_pow2(), mp_int_egcd(), mp_int_expt(), mp_int_expt_full(), mp_int_expt_value(), mp_int_exptmod(), mp_int_exptmod_known(), mp_int_free(), mp_int_gcd(), mp_int_init_copy(), mp_int_init_size(), mp_int_invmod(), mp_int_is_pow2(), mp_int_lcm(), mp_int_mul(), mp_int_mul_pow2(), mp_int_multiply_threshold(), mp_int_neg(), mp_int_read_binary(), mp_int_read_cstring(), mp_int_read_unsigned(), mp_int_redux_const(), mp_int_root(), mp_int_sqr(), mp_int_string_len(), mp_int_sub(), mp_int_to_binary(), mp_int_to_int(), mp_int_to_string(), mp_int_to_uint(), mp_int_to_unsigned(), mp_int_zero(), newarc(), newcolor(), newdfa(), NewMetaString(), newstate(), newsub(), next(), nfanode(), nfatree(), nonword(), numst(), okcolors(), parse(), generate_unaccent_rules::parse_cldr_latin_ascii_transliterator(), parsebranch(), parseqatom(), pg_reg_colorisbegin(), pg_reg_colorisend(), pg_reg_getcharacters(), pg_reg_getcolor(), pg_reg_getfinalstate(), pg_reg_getinitialstate(), pg_reg_getnumcharacters(), pg_reg_getnumcolors(), pg_reg_getnumoutarcs(), pg_reg_getnumstates(), pg_reg_getoutarcs(), pg_regcomp(), pg_regexec(), pg_regprefix(), processlacon(), pull(), pullback(), push(), pushfwd(), s_alloc(), s_embar(), s_kmul(), s_ksqr(), s_outlen(), s_qsub(), s_realloc(), s_udiv_knuth(), s_usqr(), s_usub(), s_val2ch(), scanplain(), shortest(), skip(), sortins(), sortouts(), specialcolors(), store_match(), subcolor(), subcolorhi(), subcoloronechr(), subcoloronerange(), subre(), subset(), uncolorchain(), word(), wordchrs(), and zaptreesubs().
#define CLEANUP_TEMP | ( | ) |
Definition at line 222 of file imath.c.
Referenced by mp_int_div(), mp_int_div_value(), mp_int_egcd(), mp_int_expt(), mp_int_expt_full(), mp_int_expt_value(), mp_int_exptmod(), mp_int_exptmod_known(), mp_int_gcd(), mp_int_invmod(), mp_int_lcm(), mp_int_mod(), mp_int_root(), s_embar(), and s_udiv_knuth().
#define DECLARE_TEMP | ( | N | ) |
Definition at line 206 of file imath.c.
Referenced by mp_int_div(), mp_int_div_value(), mp_int_egcd(), mp_int_expt(), mp_int_expt_full(), mp_int_expt_value(), mp_int_exptmod(), mp_int_exptmod_known(), mp_int_gcd(), mp_int_invmod(), mp_int_lcm(), mp_int_mod(), mp_int_root(), s_embar(), and s_udiv_knuth().
Definition at line 119 of file imath.c.
Referenced by mp_int_add_value(), mp_int_div_value(), mp_int_exptmod_bvalue(), mp_int_exptmod_evalue(), mp_int_init_uvalue(), mp_int_init_value(), mp_int_mul_value(), mp_int_set_uvalue(), mp_int_set_value(), mp_int_sub_value(), s_ufake(), and s_uvcmp().
#define REQUIRE | ( | E | ) |
Definition at line 240 of file imath.c.
Referenced by mp_int_div(), mp_int_div_value(), mp_int_egcd(), mp_int_expt(), mp_int_expt_full(), mp_int_expt_value(), mp_int_exptmod(), mp_int_exptmod_known(), mp_int_gcd(), mp_int_invmod(), mp_int_lcm(), mp_int_mod(), mp_int_root(), s_embar(), and s_udiv_knuth().
#define SWAP | ( | T, | |
A, | |||
B | |||
) |
#define TEMP | ( | K | ) | (temp_.value + (K)) |
Definition at line 234 of file imath.c.
Referenced by mp_int_div(), mp_int_div_value(), mp_int_egcd(), mp_int_expt(), mp_int_expt_full(), mp_int_expt_value(), mp_int_exptmod(), mp_int_exptmod_known(), mp_int_gcd(), mp_int_invmod(), mp_int_lcm(), mp_int_mod(), mp_int_root(), s_embar(), and s_udiv_knuth().
|
inlinestatic |
Definition at line 168 of file imath.c.
References MP_DIGITS(), MP_USED(), and mpz_t::used.
Referenced by mp_int_add(), mp_int_mul(), mp_int_read_cstring(), mp_int_sqr(), mp_int_sub(), s_ddiv(), s_qdiv(), s_qmod(), s_qmul(), s_qsub(), s_udiv_knuth(), UMUL(), and USQR().
|
inlinestatic |
Definition at line 248 of file imath.c.
References mpz_t::digits, MP_NEG, mpz_t::sign, and mpz_t::used.
Referenced by mp_int_div(), mp_int_egcd(), mp_int_exptmod(), mp_int_exptmod_known(), mp_int_gcd(), mp_int_invmod(), mp_int_mod(), mp_int_neg(), mp_int_read_cstring(), mp_int_to_string(), and s_reduce().
Definition at line 141 of file imath.c.
Referenced by mp_int_copy(), mp_int_init_copy(), s_kmul(), and s_ksqr().
Definition at line 313 of file imath.c.
References buf, MP_MEMORY, MP_OK, s_2comp(), s_2expt(), s_brmu(), s_cdig(), s_ch2val(), s_dadd(), s_dbmul(), s_ddiv(), s_dmul(), s_dp2k(), s_embar(), s_fake(), s_inlen(), s_isp2(), s_kmul(), s_ksqr(), s_norm(), s_outlen(), s_pad(), s_qdiv(), s_qmod(), s_qmul(), s_qsub(), s_reduce(), s_tobin(), s_uadd(), s_ucmp(), s_udiv_knuth(), s_ufake(), s_umul(), s_usqr(), s_usub(), s_uvcmp(), s_uvpack(), s_val2ch(), s_vcmp(), and value.
Referenced by mp_int_exptmod(), mp_int_exptmod_known(), s_embar(), and s_udiv_knuth().
Definition at line 187 of file imath.c.
Referenced by mp_int_add(), mp_int_init_copy(), mp_int_mul(), mp_int_sqr(), and mp_int_sub().
|
inlinestatic |
Definition at line 182 of file imath.c.
Referenced by mp_int_egcd(), and mp_int_gcd().
const char* mp_error_string | ( | mp_result | res | ) |
Returns a pointer to a brief, human-readable, zero-terminated string describing res
. The returned string is statically allocated and must not be freed by the caller.
Definition at line 2184 of file imath.c.
References fill(), s_error_msg, and s_unknown_err.
Referenced by mp_int_sqrt().
Sets c
to the absolute value of a
.
Definition at line 663 of file imath.c.
References assert, mp_int_copy(), MP_OK, MP_ZPOS, and mpz_t::sign.
Referenced by mp_int_egcd(), mp_int_gcd(), and mp_int_is_even().
Sets c
to the sum of a
and b
.
Definition at line 693 of file imath.c.
References assert, CLAMP(), cmp(), mpz_t::digits, MAX(), MP_DIGITS(), mp_int_zero(), MP_MEMORY, MP_OK, MP_SIGN(), MP_USED(), s_pad(), s_uadd(), s_ucmp(), s_usub(), mpz_t::sign, and mpz_t::used.
Referenced by mp_int_add_value(), mp_int_egcd(), mp_int_is_even(), and mp_int_mod().
Sets c
to the sum of a
and value
.
Definition at line 767 of file imath.c.
References mp_int_add(), MP_VALUE_DIGITS, and s_fake().
Referenced by mp_int_is_even().
mp_int mp_int_alloc | ( | void | ) |
Allocates a fresh zero-valued mpz_t
on the heap, returning NULL in case of error. The only possible error is out-of-memory.
Definition at line 479 of file imath.c.
References mp_int_init(), and px_alloc.
Referenced by mp_int_is_even(), and mp_new().
Returns the number of bytes to represent z
in 2's complement binary.
Definition at line 2116 of file imath.c.
References generate_unaccent_rules::bytes(), mp_int_count_bits(), and mp_int_unsigned_len().
Referenced by mp_int_sqrt().
void mp_int_clear | ( | mp_int | z | ) |
Releases the storage used by z
.
Definition at line 587 of file imath.c.
References mpz_t::digits, MP_DIGITS(), s_free(), and mpz_t::single.
Referenced by mp_int_free(), mp_int_is_even(), and mp_int_to_string().
Returns the comparator of a
and b
.
Definition at line 1274 of file imath.c.
References assert, cmp(), MP_SIGN(), MP_ZPOS, and s_ucmp().
Referenced by mp_int_egcd(), mp_int_mod_value(), and s_reduce().
Returns the comparator of the magnitudes of a
and b
, disregarding their signs. Neither a
nor b
is modified by the comparison.
Definition at line 1308 of file imath.c.
References assert, and s_ucmp().
Referenced by mp_int_mod_value(), and mp_int_root().
Returns the comparator of z
and the unsigned value uv
.
Definition at line 1354 of file imath.c.
References assert, MP_NEG, MP_SIGN(), and s_uvcmp().
Referenced by mp_int_mod_value(), and mp_int_to_uint().
Returns the comparator of z
and the signed value v
.
Definition at line 1335 of file imath.c.
References assert, cmp(), MP_NEG, MP_SIGN(), MP_ZPOS, and s_vcmp().
Referenced by mp_int_invmod(), mp_int_mod_value(), and mp_int_to_int().
int mp_int_compare_zero | ( | mp_int | z | ) |
Returns the comparator of z
and zero.
Definition at line 1316 of file imath.c.
References assert, mpz_t::digits, MP_SIGN(), MP_USED(), and MP_ZPOS.
Referenced by mp_int_mod_value(), and mp_int_mul().
Replaces the value of c
with a copy of the value of a
. No new memory is allocated unless a
has more significant digits than c
has allocated.
Definition at line 611 of file imath.c.
References assert, COPY(), MP_DIGITS(), MP_MEMORY, MP_OK, MP_USED(), s_pad(), mpz_t::sign, and mpz_t::used.
Referenced by mp_int_abs(), mp_int_div(), mp_int_div_pow2(), mp_int_egcd(), mp_int_expt(), mp_int_expt_full(), mp_int_exptmod(), mp_int_exptmod_known(), mp_int_gcd(), mp_int_invmod(), mp_int_is_even(), mp_int_lcm(), mp_int_mod(), mp_int_mul_pow2(), mp_int_neg(), mp_int_root(), mp_int_set_uvalue(), mp_int_set_value(), s_embar(), s_reduce(), and s_udiv_knuth().
Returns the number of significant bits in z
.
Definition at line 2038 of file imath.c.
References assert, mpz_t::digits, MP_DIGIT_BIT, and MP_USED().
Referenced by bn_to_mpi(), mp_int_binary_len(), mp_int_sqrt(), mp_int_unsigned_len(), mpi_to_bn(), pgp_elgamal_encrypt(), and s_outlen().
void mp_int_default_precision | ( | mp_size | ndigits | ) |
Sets the default number of digits allocated to an mp_int
constructed by mp_int_init_size()
with prec == 0
. Allocations are rounded up to multiples of this value. MP_DEFAULT_PREC
is the default value. Requires ndigits > 0
.
Definition at line 284 of file imath.c.
References assert, and default_precision.
Sets q
and r
to the quotent and remainder of a / b
. Division by powers of 2 is detected and handled efficiently. The remainder is pinned to 0 <= r < b
.
Either of q
or r
may be NULL, but not both, and q
and r
may not point to the same value.
Definition at line 1002 of file imath.c.
References assert, CLEANUP_TEMP, cmp(), CMPZ(), DECLARE_TEMP, mpz_t::digits, mp_int_copy(), mp_int_zero(), MP_NEG, MP_OK, MP_SIGN(), MP_UNDEF, MP_ZPOS, REQUIRE, s_isp2(), s_qdiv(), s_qmod(), s_ucmp(), s_udiv_knuth(), mpz_t::sign, and TEMP.
Referenced by mp_int_div_value(), mp_int_is_even(), mp_int_lcm(), mp_int_mod(), mp_int_root(), and s_brmu().
Sets q
and r
to the quotient and remainder of a / 2^p2
. This is a special case for division by powers of two that is more efficient than using ordinary division. Note that mp_int_div()
will automatically handle this case, this function is for cases where you have only the exponent.
Definition at line 1159 of file imath.c.
References assert, mp_int_copy(), MP_OK, s_qdiv(), and s_qmod().
Referenced by mp_int_is_even().
Sets q
and *r
to the quotent and remainder of a / value
. Division by powers of 2 is detected and handled efficiently. The remainder is pinned to 0 <= *r < b
. Either of q
or r
may be NULL.
Definition at line 1141 of file imath.c.
References CLEANUP_TEMP, DECLARE_TEMP, mp_int_div(), mp_int_to_int(), MP_OK, MP_VALUE_DIGITS, REQUIRE, s_fake(), and TEMP.
Referenced by mp_int_divisible_value(), mp_int_is_even(), and mp_int_mod_value().
Reports whether a
is divisible by v
.
Definition at line 1738 of file imath.c.
References mp_int_div_value(), and MP_OK.
Referenced by mp_int_mod_value().
Sets c
to the greatest common divisor of a
and b
, and sets x
and y
to values satisfying Bezout's identity gcd(a, b) = ax + by
.
It returns MP_UNDEF
if the GCD is undefined, such as for example if a
and b
are both zero.
Definition at line 1593 of file imath.c.
References assert, CLEANUP_TEMP, CMPZ(), DECLARE_TEMP, MIN(), mp_int_abs(), mp_int_add(), mp_int_compare(), mp_int_copy(), mp_int_is_even(), mp_int_is_odd(), mp_int_set_value(), mp_int_sub(), mp_int_zero(), MP_MEMORY, MP_OK, MP_UNDEF, MP_ZPOS, REQUIRE, s_dp2k(), s_qdiv(), s_qmul(), and TEMP.
Referenced by mp_int_invmod(), and mp_int_mod_value().
Sets c
to the value of a
raised to the b
power. It returns MP_RANGE
if b < 0
.
Definition at line 1179 of file imath.c.
References assert, CLEANUP_TEMP, DECLARE_TEMP, mp_int_copy(), mp_int_mul(), mp_int_set_value(), mp_int_sqr(), MP_OK, MP_RANGE, REQUIRE, and TEMP.
Referenced by mp_int_is_even(), and mp_int_root().
Sets c
to the value of a
raised to the b
power. It returns MP_RANGE
) if b < 0
.
Definition at line 1241 of file imath.c.
References assert, CLEANUP_TEMP, DECLARE_TEMP, mpz_t::digits, MP_DIGIT_BIT, mp_int_copy(), mp_int_mul(), mp_int_set_value(), mp_int_sqr(), MP_NEG, MP_OK, MP_RANGE, MP_SIGN(), MP_USED(), REQUIRE, and TEMP.
Referenced by mp_int_is_even().
Sets c
to the value of a
raised to the b
power. It returns MP_RANGE
if b < 0
.
Definition at line 1210 of file imath.c.
References assert, CLEANUP_TEMP, DECLARE_TEMP, mp_int_mul(), mp_int_set_value(), mp_int_sqr(), MP_OK, MP_RANGE, REQUIRE, and TEMP.
Referenced by mp_int_is_even().
Sets c
to the value of a
raised to the b
power, reduced modulo m
. It returns MP_RANGE
if b < 0
or MP_UNDEF
if m == 0
.
Definition at line 1369 of file imath.c.
References assert, CLEANUP_TEMP, CMPZ(), DECLARE_TEMP, GROW(), mp_int_copy(), mp_int_mod(), MP_OK, MP_RANGE, MP_UNDEF, MP_USED(), REQUIRE, s_brmu(), s_embar(), and TEMP.
Referenced by mp_int_exptmod_bvalue(), mp_int_exptmod_evalue(), mp_int_mod_value(), pgp_elgamal_decrypt(), pgp_elgamal_encrypt(), pgp_rsa_decrypt(), and pgp_rsa_encrypt().
Sets c
to the value of value
raised to the b
power, modulo m
. It returns MP_RANGE
if b < 0
or MP_UNDEF
if m == 0
.
Definition at line 1418 of file imath.c.
References mp_int_exptmod(), MP_VALUE_DIGITS, and s_fake().
Referenced by mp_int_mod_value().
Sets c
to the value of a
raised to the value
power, modulo m
. It returns MP_RANGE
if value < 0
or MP_UNDEF
if m == 0
.
Definition at line 1407 of file imath.c.
References mp_int_exptmod(), MP_VALUE_DIGITS, and s_fake().
Referenced by mp_int_mod_value().
Sets c
to the value of a
raised to the b
power, reduced modulo m
, given a precomputed reduction constant mu
defined for Barrett's modular reduction algorithm.
It returns MP_RANGE
if b < 0
or MP_UNDEF
if m == 0
.
Definition at line 1429 of file imath.c.
References assert, CLEANUP_TEMP, CMPZ(), DECLARE_TEMP, GROW(), mp_int_copy(), mp_int_mod(), MP_OK, MP_RANGE, MP_UNDEF, MP_USED(), REQUIRE, s_embar(), and TEMP.
Referenced by mp_int_mod_value().
void mp_int_free | ( | mp_int | z | ) |
Releases the storage used by z
and also z
itself. This should only be used for z
allocated by mp_int_alloc()
.
Definition at line 602 of file imath.c.
References assert, mp_int_clear(), and px_free.
Referenced by mp_clear_free(), and mp_int_is_even().
Sets c
to the greatest common divisor of a
and b
.
It returns MP_UNDEF
if the GCD is undefined, such as for example if a
and b
are both zero.
Definition at line 1514 of file imath.c.
References assert, CLEANUP_TEMP, CMPZ(), DECLARE_TEMP, MIN(), mp_int_abs(), mp_int_copy(), mp_int_is_odd(), mp_int_neg(), mp_int_sub(), MP_MEMORY, MP_OK, MP_UNDEF, MP_ZPOS, REQUIRE, s_dp2k(), s_qdiv(), s_qmul(), and TEMP.
Referenced by mp_int_lcm(), and mp_int_mod_value().
Initializes z
with 1-digit precision and sets it to zero. This function cannot fail unless z == NULL
.
Definition at line 464 of file imath.c.
References mpz_t::alloc, mpz_t::digits, MP_BADARG, MP_OK, MP_ZPOS, mpz_t::sign, mpz_t::single, and mpz_t::used.
Referenced by mp_int_alloc(), mp_int_init_copy(), mp_int_init_size(), and mp_int_is_even().
Initializes z
to be a copy of an already-initialized value in old
. The new copy does not share storage with the original.
Definition at line 520 of file imath.c.
References assert, COPY(), default_precision, MAX(), MP_DIGITS(), mp_int_init(), mp_int_init_size(), MP_OK, MP_USED(), mpz_t::sign, and mpz_t::used.
Referenced by mp_int_init_uvalue(), mp_int_init_value(), mp_int_is_even(), and mp_int_to_string().
Initializes z
with at least prec
digits of storage, and sets it to zero. If prec
is zero, the default precision is used. In either case the size is rounded up to the nearest multiple of the word size.
Definition at line 490 of file imath.c.
References mpz_t::alloc, assert, default_precision, mpz_t::digits, MP_DIGITS(), mp_int_init(), MP_MEMORY, MP_OK, MP_ZPOS, s_alloc(), s_round_prec(), mpz_t::sign, and mpz_t::used.
Referenced by mp_int_init_copy(), mp_int_is_even(), and mp_new().
Initializes z
to the specified unsigned value
at default precision.
Definition at line 557 of file imath.c.
References mp_int_init_copy(), MP_VALUE_DIGITS, and s_ufake().
Referenced by mp_int_is_even().
Initializes z
to the specified signed value
at default precision.
Definition at line 547 of file imath.c.
References mp_int_init_copy(), MP_VALUE_DIGITS, and s_fake().
Referenced by mp_int_is_even().
Sets c
to the multiplicative inverse of a
modulo m
, if it exists. The least non-negative representative of the congruence class is computed.
It returns MP_UNDEF
if the inverse does not exist, or MP_RANGE
if a == 0
or m <= 0
.
Definition at line 1474 of file imath.c.
References assert, CLEANUP_TEMP, CMPZ(), DECLARE_TEMP, mp_int_compare_value(), mp_int_copy(), mp_int_egcd(), mp_int_mod(), mp_int_sub(), MP_NEG, MP_OK, MP_RANGE, MP_SIGN(), MP_UNDEF, REQUIRE, and TEMP.
Referenced by mp_int_mod_value(), and pgp_elgamal_decrypt().
int mp_int_is_pow2 | ( | mp_int | z | ) |
Returns k >= 0
such that z
is 2^k
, if such a k
exists. If no such k
exists, the function returns -1.
Definition at line 1750 of file imath.c.
References assert, and s_isp2().
Referenced by mp_int_mod_value().
Sets c
to the least common multiple of a
and b
.
It returns MP_UNDEF
if the LCM is undefined, such as for example if a
and b
are both zero.
Definition at line 1716 of file imath.c.
References assert, CLEANUP_TEMP, DECLARE_TEMP, mp_int_copy(), mp_int_div(), mp_int_gcd(), mp_int_mul(), MP_OK, REQUIRE, and TEMP.
Referenced by mp_int_mod_value().
Sets c
to the remainder of a / m
. The remainder is pinned to 0 <= c < m
.
Definition at line 1122 of file imath.c.
References CLEANUP_TEMP, CMPZ(), DECLARE_TEMP, mp_int_add(), mp_int_copy(), mp_int_div(), MP_OK, REQUIRE, and TEMP.
Referenced by mp_int_exptmod(), mp_int_exptmod_known(), mp_int_invmod(), mp_int_is_even(), and mp_modmul().
Sets c
to the product of a
and b
.
Definition at line 857 of file imath.c.
References assert, CLAMP(), default_precision, MAX(), MP_DIGITS(), mp_int_compare_zero(), mp_int_zero(), MP_MEMORY, MP_NEG, MP_OK, MP_SIGN(), MP_USED(), MP_ZPOS, s_alloc(), s_free(), s_kmul(), s_pad(), s_round_prec(), mpz_t::sign, mpz_t::used, and ZERO().
Referenced by mp_int_expt(), mp_int_expt_full(), mp_int_expt_value(), mp_int_is_even(), mp_int_lcm(), mp_int_mul_value(), and mp_modmul().
Sets c
to the product of a
and 2^p2
. Requires p2 >= 0
.
Definition at line 934 of file imath.c.
References assert, mp_int_copy(), MP_MEMORY, MP_OK, and s_qmul().
Referenced by mp_int_is_even().
Sets c
to the product of a
and value
.
Definition at line 923 of file imath.c.
References mp_int_mul(), MP_VALUE_DIGITS, and s_fake().
Referenced by mp_int_is_even(), and mp_int_root().
void mp_int_multiply_threshold | ( | mp_size | ndigits | ) |
Sets the number of digits below which multiplication will use the standard quadratic "schoolbook" multiplcation algorithm rather than Karatsuba-Ofman. Requires ndigits >= sizeof(mp_word)
.
Definition at line 294 of file imath.c.
References assert, multiply_threshold, s_alloc(), s_free(), and s_pad().
Sets c
to the additive inverse (negation) of a
.
Definition at line 677 of file imath.c.
References assert, CMPZ(), mp_int_copy(), MP_OK, MP_SIGN(), and mpz_t::sign.
Referenced by mp_int_gcd(), mp_int_is_even(), and mp_int_root().
Reads a 2's complement binary value from buf
into z
, where len
is the length of the buffer. The contents of buf
may be overwritten during processing, although they will be restored when the function returns.
Definition at line 2077 of file imath.c.
References assert, buf, i, MP_DIGIT_BIT, MP_DIGITS(), mp_int_zero(), MP_MEMORY, MP_NEG, MP_OK, MP_SIGN(), s_2comp(), s_pad(), s_qmul(), and mpz_t::sign.
Referenced by mp_int_sqrt().
Reads a string of ASCII digits in the specified radix
from the zero terminated str
provided into z
. For values of radix > 10
, the letters A
..Z
or a
..z
are accepted. Letters are interpreted without respect to case.
Leading whitespace is ignored, and a leading +
or -
is interpreted as a sign flag. Processing stops when a NUL or any other character out of range for a digit in the given radix is encountered.
If the whole string was consumed, MP_OK
is returned; otherwise MP_TRUNC
. is returned. If end
is not NULL, *end
is set to point to the first unconsumed byte of the input string (the NUL byte if the whole string was consumed). This emulates the behavior of the standard C strtol()
function.
Requires MP_MIN_RADIX <= radix <= MP_MAX_RADIX
.
Definition at line 1970 of file imath.c.
References assert, CLAMP(), CMPZ(), mpz_t::digits, MP_MAX_RADIX, MP_MEMORY, MP_MIN_RADIX, MP_NEG, MP_OK, MP_TRUNC, MP_ZPOS, s_ch2val(), s_dadd(), s_dmul(), s_inlen(), s_pad(), mpz_t::sign, generate_unaccent_rules::str, unconstify, and mpz_t::used.
Referenced by mp_int_read_string(), and mp_int_sqrt().
Reads a string of ASCII digits in the specified radix
from the zero terminated str
provided into z
. For values of radix > 10
, the letters A
..Z
or a
..z
are accepted. Letters are interpreted without respect to case.
Leading whitespace is ignored, and a leading +
or -
is interpreted as a sign flag. Processing stops when a NUL or any other character out of range for a digit in the given radix is encountered.
If the whole string was consumed, MP_OK
is returned; otherwise MP_TRUNC
. is returned.
Requires MP_MIN_RADIX <= radix <= MP_MAX_RADIX
.
Definition at line 1964 of file imath.c.
References mp_int_read_cstring().
Referenced by mp_int_sqrt().
Reads an unsigned binary value from buf
into z
, where len
is the length of the buffer. The contents of buf
are not modified during processing.
Definition at line 2147 of file imath.c.
References assert, buf, i, MP_DIGIT_BIT, MP_DIGITS(), mp_int_zero(), MP_MEMORY, MP_OK, s_pad(), and s_qmul().
Referenced by mp_int_sqrt(), mp_px_rand(), and mpi_to_bn().
Sets c
to the reduction constant for Barrett reduction by modulus m
. Requires that c
and m
point to distinct locations.
Definition at line 1466 of file imath.c.
References assert, and s_brmu().
Referenced by mp_int_mod_value().
Sets c
to the greatest integer not less than the b
th root of a
, using Newton's root-finding algorithm. It returns MP_UNDEF
if a < 0
and b
is even.
Definition at line 1762 of file imath.c.
References assert, CLEANUP_TEMP, DECLARE_TEMP, mp_int_compare_unsigned(), mp_int_copy(), mp_int_div(), mp_int_expt(), mp_int_mul_value(), mp_int_neg(), mp_int_sub(), mp_int_sub_value(), MP_NEG, MP_OK, MP_SIGN(), MP_UNDEF, MP_ZPOS, REQUIRE, and TEMP.
Referenced by mp_int_mod_value(), and mp_int_sqrt().
Sets z
to the value of the specified unsigned value
.
Definition at line 577 of file imath.c.
References mp_int_copy(), MP_VALUE_DIGITS, and s_ufake().
Referenced by mp_int_is_even().
Sets z
to the value of the specified signed value
.
Definition at line 567 of file imath.c.
References mp_int_copy(), MP_VALUE_DIGITS, and s_fake().
Referenced by mp_int_egcd(), mp_int_expt(), mp_int_expt_full(), mp_int_expt_value(), mp_int_is_even(), s_embar(), and s_udiv_knuth().
Sets c
to the square of a
.
Definition at line 954 of file imath.c.
References assert, CLAMP(), default_precision, MAX(), MP_DIGITS(), MP_MEMORY, MP_OK, MP_USED(), MP_ZPOS, s_alloc(), s_free(), s_ksqr(), s_pad(), s_round_prec(), mpz_t::sign, mpz_t::used, and ZERO().
Referenced by mp_int_expt(), mp_int_expt_full(), mp_int_expt_value(), and mp_int_is_even().
Reports the minimum number of characters required to represent z
as a zero-terminated string in the given radix
. Requires MP_MIN_RADIX <= radix <= MP_MAX_RADIX
.
Definition at line 1948 of file imath.c.
References assert, MP_MAX_RADIX, MP_MIN_RADIX, MP_NEG, MP_SIGN(), and s_outlen().
Referenced by mp_int_sqrt().
Sets c
to the difference of a
less b
.
Definition at line 778 of file imath.c.
References assert, CLAMP(), cmp(), mpz_t::digits, MAX(), MP_DIGITS(), MP_MEMORY, MP_NEG, MP_OK, MP_SIGN(), MP_USED(), MP_ZPOS, s_pad(), s_uadd(), s_ucmp(), s_usub(), mpz_t::sign, and mpz_t::used.
Referenced by mp_int_egcd(), mp_int_gcd(), mp_int_invmod(), mp_int_is_even(), mp_int_root(), mp_int_sub_value(), and s_reduce().
Sets c
to the difference of a
less value
.
Definition at line 846 of file imath.c.
References mp_int_sub(), MP_VALUE_DIGITS, and s_fake().
Referenced by mp_int_is_even(), and mp_int_root().
Swaps the values and storage between a
and c
.
Definition at line 636 of file imath.c.
References mpz_t::digits, MP_DIGITS(), and mpz_t::single.
Referenced by mp_int_is_even().
Converts z
to 2's complement binary, writing at most limit
bytes into the given buf
. Returns MP_TRUNC
if the buffer limit was too small to contain the whole value. If this occurs, the contents of buf will be effectively garbage, as the function uses the buffer as scratch space.
The binary representation of z
is in base-256 with digits ordered from most significant to least significant (network byte ordering). The high-order bit of the first byte is set for negative values, clear for non-negative values.
As a result, non-negative values will be padded with a leading zero byte if the high-order byte of the base-256 magnitude is set. This extra byte is accounted for by the mp_int_binary_len()
function.
Definition at line 2061 of file imath.c.
References assert, MP_NEG, MP_SIGN(), s_2comp(), and s_tobin().
Referenced by mp_int_sqrt().
Returns MP_OK
if z
is representable as mp_small
, else MP_RANGE
. If out
is not NULL, *out
is set to the value of z
when MP_OK
.
Definition at line 1822 of file imath.c.
References assert, MP_DIGIT_BIT, MP_DIGITS(), mp_int_compare_value(), MP_NEG, MP_OK, MP_RANGE, MP_SIGN(), MP_SMALL_MAX, MP_SMALL_MIN, MP_USED(), and MP_ZPOS.
Referenced by mp_int_div_value(), and mp_int_sqrt().
Converts z
to a zero-terminated string of characters in the specified radix
, writing at most limit
characters to str
including the terminating NUL value. A leading -
is used to indicate a negative value.
Returns MP_TRUNC
if limit
was to small to write all of z
. Requires MP_MIN_RADIX <= radix <= MP_MAX_RADIX
.
Definition at line 1883 of file imath.c.
References assert, cmp(), CMPZ(), mp_int_clear(), mp_int_init_copy(), MP_MAX_RADIX, MP_MIN_RADIX, MP_NEG, MP_OK, MP_SIGN(), MP_TRUNC, s_ddiv(), s_val2ch(), and generate_unaccent_rules::str.
Referenced by mp_int_sqrt().
Returns MP_OK
if z
is representable as mp_usmall
, or MP_RANGE
. If out
is not NULL, *out
is set to the value of z
when MP_OK
.
Definition at line 1853 of file imath.c.
References assert, MP_DIGIT_BIT, MP_DIGITS(), mp_int_compare_uvalue(), MP_NEG, MP_OK, MP_RANGE, MP_SIGN(), MP_USED(), and MP_USMALL_MAX.
Referenced by mp_int_sqrt().
Converts the magnitude of z
to unsigned binary, writing at most limit
bytes into the given buf
. The sign of z
is ignored, but z
is not modified. Returns MP_TRUNC
if the buffer limit was too small to contain the whole value. If this occurs, the contents of buf
will be effectively garbage, as the function uses the buffer as scratch space during conversion.
The binary representation of z
is in base-256 with digits ordered from most significant to least significant (network byte ordering).
Definition at line 2137 of file imath.c.
References assert, and s_tobin().
Referenced by bn_to_mpi(), and mp_int_sqrt().
Returns the number of bytes required to represent z
as an unsigned binary value in base 256.
Definition at line 2171 of file imath.c.
References generate_unaccent_rules::bytes(), and mp_int_count_bits().
Referenced by mp_int_binary_len(), and mp_int_sqrt().
void mp_int_zero | ( | mp_int | z | ) |
Sets z
to zero. The allocated storage of z
is not changed.
Definition at line 653 of file imath.c.
References assert, mpz_t::digits, MP_ZPOS, mpz_t::sign, and mpz_t::used.
Referenced by mp_int_add(), mp_int_div(), mp_int_egcd(), mp_int_is_even(), mp_int_mul(), mp_int_read_binary(), mp_int_read_unsigned(), and s_qdiv().
|
inlinestatic |
|
static |
Definition at line 3519 of file imath.c.
References i.
Referenced by GROW(), mp_int_read_binary(), and mp_int_to_binary().
Definition at line 3038 of file imath.c.
References MP_DIGIT_BIT, MP_DIGITS(), s_pad(), mpz_t::used, and ZERO().
Referenced by GROW(), and s_brmu().
Definition at line 2213 of file imath.c.
References assert, fill(), and px_alloc.
Referenced by mp_int_init_size(), mp_int_mul(), mp_int_multiply_threshold(), mp_int_sqr(), s_kmul(), s_ksqr(), s_pad(), and s_realloc().
Definition at line 3081 of file imath.c.
References MP_DIGIT_BIT, mp_int_div(), MP_MEMORY, MP_USED(), s_2expt(), and s_pad().
Referenced by GROW(), mp_int_exptmod(), and mp_int_redux_const().
|
static |
Definition at line 2707 of file imath.c.
References LOWER_HALF(), MP_DIGITS(), MP_USED(), UPPER_HALF(), and mpz_t::used.
Referenced by GROW(), and mp_int_read_cstring().
Definition at line 2755 of file imath.c.
References LOWER_HALF(), and UPPER_HALF().
Referenced by GROW(), and s_udiv_knuth().
Definition at line 2773 of file imath.c.
References CLAMP(), MP_DIGIT_BIT, MP_DIGITS(), and MP_USED().
Referenced by GROW(), mp_int_to_string(), and s_udiv_knuth().
Definition at line 2733 of file imath.c.
References LOWER_HALF(), MP_DIGITS(), MP_USED(), UPPER_HALF(), and mpz_t::used.
Referenced by GROW(), and mp_int_read_cstring().
|
static |
Definition at line 2984 of file imath.c.
References MP_DIGIT_BIT, MP_DIGITS(), and MP_USED().
Referenced by GROW(), mp_int_egcd(), and mp_int_gcd().
Definition at line 3149 of file imath.c.
References assert, CLEANUP_TEMP, DECLARE_TEMP, digits, GROW(), i, MP_DIGIT_BIT, MP_DIGITS(), mp_int_copy(), mp_int_set_value(), MP_MEMORY, MP_OK, MP_SIGN(), MP_USED(), MP_ZPOS, REQUIRE, s_reduce(), TEMP, UMUL(), USQR(), and ZERO().
Referenced by GROW(), mp_int_exptmod(), and mp_int_exptmod_known().
Definition at line 2280 of file imath.c.
References MP_NEG, s_ufake(), mpz_t::sign, and value.
Referenced by GROW(), mp_int_add_value(), mp_int_div_value(), mp_int_exptmod_bvalue(), mp_int_exptmod_evalue(), mp_int_init_value(), mp_int_mul_value(), mp_int_set_value(), and mp_int_sub_value().
|
static |
Definition at line 2247 of file imath.c.
References px_free.
Referenced by mp_int_clear(), mp_int_mul(), mp_int_multiply_threshold(), mp_int_sqr(), s_kmul(), and s_ksqr().
Definition at line 3465 of file imath.c.
References MP_DIGIT_BIT, and s_log2.
Referenced by GROW(), and mp_int_read_cstring().
|
static |
Definition at line 3010 of file imath.c.
References MP_DIGIT_BIT, MP_DIGITS(), and MP_USED().
Referenced by GROW(), mp_int_div(), and mp_int_is_pow2().
|
static |
Definition at line 2458 of file imath.c.
References assert, COPY(), multiply_threshold, s_alloc(), s_free(), s_uadd(), s_umul(), s_usub(), SWAP, and ZERO().
Referenced by GROW(), mp_int_mul(), s_ksqr(), and UMUL().
Definition at line 2582 of file imath.c.
References assert, COPY(), i, LOWER_HALF(), multiply_threshold, PG_USED_FOR_ASSERTS_ONLY, s_alloc(), s_free(), s_kmul(), s_uadd(), s_usqr(), UPPER_HALF(), and ZERO().
Referenced by GROW(), mp_int_sqr(), and USQR().
Definition at line 3059 of file imath.c.
References mpz_t::digits, MP_DIGIT_BIT, MP_USED(), and s_qmul().
Referenced by GROW(), and s_udiv_knuth().
Definition at line 3454 of file imath.c.
References assert, mp_int_count_bits(), MP_MAX_RADIX, MP_MIN_RADIX, and s_log2.
Referenced by GROW(), and mp_int_string_len().
Definition at line 2253 of file imath.c.
References mpz_t::alloc, mpz_t::digits, MP_ALLOC(), MP_DIGITS(), s_alloc(), s_realloc(), s_round_prec(), and mpz_t::single.
Referenced by GROW(), mp_int_add(), mp_int_copy(), mp_int_mul(), mp_int_multiply_threshold(), mp_int_read_binary(), mp_int_read_cstring(), mp_int_read_unsigned(), mp_int_sqr(), mp_int_sub(), px_find_combo(), s_2expt(), s_brmu(), s_qmul(), s_qsub(), and s_udiv_knuth().
Definition at line 2802 of file imath.c.
References CLAMP(), mpz_t::digits, MP_DIGIT_BIT, MP_DIGITS(), mp_int_zero(), MP_USED(), MP_ZPOS, mpz_t::sign, and mpz_t::used.
Referenced by GROW(), mp_int_div(), mp_int_div_pow2(), mp_int_egcd(), mp_int_gcd(), s_reduce(), and s_udiv_knuth().
Definition at line 2857 of file imath.c.
References CLAMP(), mpz_t::digits, MP_DIGIT_BIT, MP_USED(), and mpz_t::used.
Referenced by GROW(), mp_int_div(), mp_int_div_pow2(), and s_reduce().
Definition at line 2873 of file imath.c.
References CLAMP(), i, MP_DIGIT_BIT, MP_DIGITS(), MP_USED(), s_pad(), mpz_t::used, and ZERO().
Referenced by GROW(), mp_int_egcd(), mp_int_gcd(), mp_int_mul_pow2(), mp_int_read_binary(), mp_int_read_unsigned(), and s_norm().
Definition at line 2953 of file imath.c.
References assert, CLAMP(), LOWER_HALF(), MP_DIGIT_BIT, MP_DIGIT_MAX, MP_DIGITS(), MP_ZPOS, s_pad(), mpz_t::sign, and UPPER_HALF().
Referenced by GROW(), and s_reduce().
Definition at line 3093 of file imath.c.
References CMPZ(), MP_DIGIT_BIT, mp_int_compare(), mp_int_copy(), mp_int_sub(), MP_OK, MP_USED(), s_qdiv(), s_qmod(), s_qsub(), and UMUL().
Referenced by GROW(), and s_embar().
Definition at line 124 of file imath.c.
Referenced by mp_int_init_size(), mp_int_mul(), mp_int_sqr(), and s_pad().
Definition at line 3538 of file imath.c.
References i, MP_DIGITS(), MP_OK, MP_TRUNC, MP_USED(), and REV().
Referenced by GROW(), mp_int_to_binary(), and mp_int_to_unsigned().
|
static |
Definition at line 2387 of file imath.c.
References LOWER_HALF(), SWAP, and UPPER_HALF().
Referenced by GROW(), mp_int_add(), mp_int_sub(), s_kmul(), and s_ksqr().
Definition at line 2342 of file imath.c.
References MP_DIGITS(), MP_USED(), and s_cdig().
Referenced by GROW(), mp_int_add(), mp_int_compare(), mp_int_compare_unsigned(), mp_int_div(), mp_int_sub(), s_udiv_knuth(), and s_uvcmp().
Definition at line 3248 of file imath.c.
References mpz_t::alloc, assert, CLAMP(), CLEANUP_TEMP, DECLARE_TEMP, mpz_t::digits, digits, GROW(), MP_ALLOC(), MP_DIGIT_BIT, MP_DIGIT_MAX, MP_DIGITS(), mp_int_copy(), mp_int_set_value(), MP_MEMORY, MP_OK, MP_USED(), MP_ZPOS, REQUIRE, s_dbmul(), s_ddiv(), s_norm(), s_pad(), s_qdiv(), s_ucmp(), s_usub(), mpz_t::sign, TEMP, mpz_t::used, and ZERO().
Referenced by GROW(), and mp_int_div().