Crate creachadair_imath_sys

Source

Structs§

mpq_t
mpz_t

Constants§

MP_MAX_RADIX
MP_MIN_RADIX
mp_round_mode_MP_ROUND_DOWN
mp_round_mode_MP_ROUND_HALF_DOWN
mp_round_mode_MP_ROUND_HALF_UP
mp_round_mode_MP_ROUND_UP

Statics§

MP_BADARG
MP_FALSE
MP_MEMORY
MP_MINERR
MP_NEG
A sign indicating a (strictly) negative value.
MP_OK
MP_RANGE
MP_TRUE
MP_TRUNC
MP_UNDEF
MP_ZPOS
A sign indicating a zero or positive value.

Functions§

mp_error_string
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.
mp_int_abs
Sets c to the absolute value of a.
mp_int_add
Sets c to the sum of a and b.
mp_int_add_value
Sets c to the sum of a and value.
mp_int_alloc
Allocates a fresh zero-valued mpz_t on the heap, returning NULL in case of error. The only possible error is out-of-memory.
mp_int_binary_len
Returns the number of bytes to represent z in 2’s complement binary.
mp_int_clear
Releases the storage used by z.
mp_int_compare
Returns the comparator of a and b.
mp_int_compare_unsigned
Returns the comparator of the magnitudes of a and b, disregarding their signs. Neither a nor b is modified by the comparison.
mp_int_compare_uvalue
Returns the comparator of z and the unsigned value uv.
mp_int_compare_value
Returns the comparator of z and the signed value v.
mp_int_compare_zero
Returns the comparator of z and zero.
mp_int_copy
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.
mp_int_count_bits
Returns the number of significant bits in z.
mp_int_default_precision
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.
mp_int_div
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.
mp_int_div_pow2
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.
mp_int_div_value
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.
mp_int_divisible_value
Reports whether a is divisible by v.
mp_int_egcd
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.
mp_int_expt
Sets c to the value of a raised to the b power. It returns MP_RANGE if b < 0.
mp_int_expt_full
Sets c to the value of a raised to the b power. It returns MP_RANGE) if b < 0.
mp_int_expt_value
Sets c to the value of a raised to the b power. It returns MP_RANGE if b < 0.
mp_int_exptmod
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.
mp_int_exptmod_bvalue
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.
mp_int_exptmod_evalue
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.
mp_int_exptmod_known
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.
mp_int_find_prime
mp_int_free
Releases the storage used by z and also z itself. This should only be used for z allocated by mp_int_alloc().
mp_int_gcd
Sets c to the greatest common divisor of a and b.
mp_int_init
Initializes z with 1-digit precision and sets it to zero. This function cannot fail unless z == NULL.
mp_int_init_copy
Initializes z to be a copy of an already-initialized value in old. The new copy does not share storage with the original.
mp_int_init_size
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.
mp_int_init_uvalue
Initializes z to the specified unsigned value at default precision.
mp_int_init_value
Initializes z to the specified signed value at default precision.
mp_int_invmod
Sets c to the multiplicative inverse of a modulo m, if it exists. The least non-negative representative of the congruence class is computed.
mp_int_is_pow2
Returns k >= 0 such that z is 2^k, if such a k exists. If no such k exists, the function returns -1.
mp_int_is_prime
mp_int_lcm
Sets c to the least common multiple of a and b.
mp_int_mod
Sets c to the remainder of a / m. The remainder is pinned to 0 <= c < m.
mp_int_mul
Sets c to the product of a and b.
mp_int_mul_pow2
Sets c to the product of a and 2^p2. Requires p2 >= 0.
mp_int_mul_value
Sets c to the product of a and value.
mp_int_multiply_threshold
Sets the number of digits below which multiplication will use the standard quadratic “schoolbook” multiplication algorithm rather than Karatsuba-Ofman. Requires ndigits >= sizeof(mp_word).
mp_int_neg
Sets c to the additive inverse (negation) of a.
mp_int_read_binary
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.
mp_int_read_cstring
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.
mp_int_read_string
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.
mp_int_read_unsigned
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.
mp_int_redux_const
Sets c to the reduction constant for Barrett reduction by modulus m. Requires that c and m point to distinct locations.
mp_int_root
Sets c to the greatest integer not less than the bth root of a, using Newton’s root-finding algorithm. It returns MP_UNDEF if a < 0 and b is even.
mp_int_set_uvalue
Sets z to the value of the specified unsigned value.
mp_int_set_value
Sets z to the value of the specified signed value.
mp_int_sqr
Sets c to the square of a.
mp_int_string_len
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.
mp_int_sub
Sets c to the difference of a less b.
mp_int_sub_value
Sets c to the difference of a less value.
mp_int_swap
Swaps the values and storage between a and c.
mp_int_to_binary
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.
mp_int_to_int
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.
mp_int_to_string
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.
mp_int_to_uint
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.
mp_int_to_unsigned
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.
mp_int_unsigned_len
Returns the number of bytes required to represent z as an unsigned binary value in base 256.
mp_int_zero
Sets z to zero. The allocated storage of z is not changed.
mp_rat_abs
Sets c to the absolute value of a.
mp_rat_add
Sets c to the sum of a and b.
mp_rat_add_int
Sets c to the sum of a and integer b.
mp_rat_alloc
Allocates a fresh zero-valued mpq_t on the heap, returning NULL in case of error. The only possible error is out-of-memory.
mp_rat_clear
Releases the storage used by r.
mp_rat_compare
Returns the comparator of a and b.
mp_rat_compare_unsigned
Returns the comparator of the magnitudes of a and b, disregarding their signs. Neither a nor b is modified by the comparison.
mp_rat_compare_value
Returns the comparator of r and the signed ratio n / d. It returns MP_UNDEF if d is zero.
mp_rat_compare_zero
Returns the comparator of r and zero.
mp_rat_copy
Sets c to a copy of the value of a. No new memory is allocated unless a term of a has more significant digits than the corresponding term of c has allocated.
mp_rat_decimal_len
Reports the length in bytes of the buffer needed to convert r using the mp_rat_to_decimal() function with the specified radix and prec. The buffer size estimate may slightly exceed the actual required capacity.
mp_rat_denom
Sets z to a copy of the denominator of r.
mp_rat_denom_ref
Returns a pointer to the denominator of r.
mp_rat_div
Sets c to the ratio a / b if that ratio is defined. It returns MP_UNDEF if b is zero.
mp_rat_div_int
Sets c to the ratio a / b if that ratio is defined. It returns MP_UNDEF if b is zero.
mp_rat_expt
Sets c to the value of a raised to the b power. It returns MP_RANGE if b < 0.
mp_rat_free
Releases the storage used by r and also r itself. This should only be used for r allocated by mp_rat_alloc().
mp_rat_init
Initializes r with 1-digit precision and sets it to zero. This function cannot fail unless r is NULL.
mp_rat_init_copy
Initializes r to be a copy of an already-initialized value in old. The new copy does not share storage with the original.
mp_rat_init_size
Initializes r with at least n_prec digits of storage for the numerator and d_prec digits of storage for the denominator, and value zero.
mp_rat_is_integer
Reports whether r is an integer, having canonical denominator 1.
mp_rat_mul
Sets c to the product of a and b.
mp_rat_mul_int
Sets c to the product of a and integer b.
mp_rat_neg
Sets c to the absolute value of a.
mp_rat_numer
Sets z to a copy of the numerator of r.
mp_rat_numer_ref
Returns a pointer to the numerator of r.
mp_rat_read_cdecimal
Sets r to the value represented by a zero-terminated string str in the format "z.ffff" including a sign flag. It returns MP_UNDEF if the effective denominator is zero. If end is not NULL then *end is set to point to the first unconsumed character in the string, after parsing.
mp_rat_read_cstring
Sets r to the value represented by a zero-terminated string str in the format "n/d" including a sign flag. It returns MP_UNDEF if the encoded denominator has value zero. If end is not NULL then *end is set to point to the first unconsumed character in the string, after parsing.
mp_rat_read_decimal
Sets r to the value represented by a zero-terminated string str in the format "z.ffff" including a sign flag. It returns MP_UNDEF if the effective denominator is zero.
mp_rat_read_string
Sets r to the value represented by a zero-terminated string str in the format "n/d" including a sign flag. It returns MP_UNDEF if the encoded denominator has value zero.
mp_rat_read_ustring
Sets r to the value represented by a zero-terminated string str having one of the following formats, each with an optional leading sign flag:
mp_rat_recip
Sets c to the reciprocal of a if the reciprocal is defined. It returns MP_UNDEF if a is zero.
mp_rat_reduce
Reduces r in-place to lowest terms and canonical form.
mp_rat_set_uvalue
Sets the value of r to the ratio of unsigned numer to unsigned denom. It returns MP_UNDEF if denom is zero.
mp_rat_set_value
Sets the value of r to the ratio of signed numer to signed denom. It returns MP_UNDEF if denom is zero.
mp_rat_sign
Reports the sign of r.
mp_rat_string_len
Reports the minimum number of characters required to represent r as a zero-terminated string in the given radix. Requires MP_MIN_RADIX <= radix <= MP_MAX_RADIX.
mp_rat_sub
Sets c to the difference of a less b.
mp_rat_sub_int
Sets c to the difference of a less integer b.
mp_rat_to_decimal
Converts the value of r to a string in decimal-point notation with the specified radix, writing no more than limit bytes of data to the given output buffer. It generates prec digits of precision, and requires MP_MIN_RADIX <= radix <= MP_MAX_RADIX.
mp_rat_to_ints
Reports whether the numerator and denominator of r can be represented as small signed integers, and if so stores the corresponding values to num and den. It returns MP_RANGE if either cannot be so represented.
mp_rat_to_string
Converts r to a zero-terminated string of the format "n/d" with n and d in the specified radix and writing no more than limit bytes to the given output buffer str. The output of the numerator includes a sign flag if r is negative. Requires MP_MIN_RADIX <= radix <= MP_MAX_RADIX.
mp_rat_zero
Sets r to zero. The allocated storage of r is not changed.

Type Aliases§

mp_digit
mp_int
mp_rat
mp_result
mp_round_mode
mp_sign
mp_size
mp_small
mp_usmall
mp_word