Go to the previous, next section.

These functions are intended to be fully compatible with the Berkeley MP library which is available on many BSD derived U*ix systems.

The original Berkeley MP library has a usage restriction: you cannot use the same variable as both source and destination in a single function call. The compatible functions in GNU MP do not share this restriction--inputs and outputs may overlap.

It is not recommended that new programs are written using these
functions. Apart from the incomplete set of functions, the interface
for initializing `MINT`

objects is more error prone, and the
`pow`

function collides with `pow`

in ``libm.a'`.

Include the header ``mp.h'` to get the definition of the necessary
types and functions. If you are on a BSD derived system, make sure to
include GNU ``mp.h'` if you are going to link the GNU ``libmp.a'`
to you program. This means that you probably need to give the -I<dir>
option to the compiler, where <dir> is the directory where you have GNU
``mp.h'`.

__Function:__ MINT * **itom** *(signed short int initial_value)*

Allocate an integer consisting of a `MINT`

object and dynamic limb
space. Initialize the integer to `initial_value`. Return a pointer
to the `MINT`

object.

__Function:__ MINT * **xtom** *(char * initial_value)*

Allocate an integer consisting of a `MINT`

object and dynamic limb
space. Initialize the integer from `initial_value`, a hexadecimal,
'\0'-terminate C string. Return a pointer to the `MINT`

object.

__Function:__ void **move** *(MINT * src, MINT *dest)*

Set `dest` to `src` by copying. Both variables must be
previously initialized.

__Function:__ void **madd** *(MINT * src_1, MINT *src_2, MINT *destination)*

Add `src_1` and `src_2` and put the sum in `destination`.

__Function:__ void **msub** *(MINT * src_1, MINT *src_2, MINT *destination)*

Subtract `src_2` from `src_1` and put the difference in
`destination`.

__Function:__ void **mult** *(MINT * src_1, MINT *src_2, MINT *destination)*

Multiply `src_1` and `src_2` and put the product in
`destination`.

__Function:__ void **mdiv** *(MINT * dividend, MINT *divisor, MINT *quotient, MINT *remainder)*

__Function:__ void **sdiv** *(MINT * dividend, signed short int divisor, MINT *quotient, signed short int *remainder)*

Set `quotient` to `dividend` / `divisor`, and
`remainder` to `dividend` mod `divisor`. The quotient is
rounded towards zero; the remainder has the same sign as the dividend.

Some implementations of this function return a remainder whose sign is inverted if the divisor is negative. Such a definition makes little sense from a mathematical point of view. GNU MP might be considered incompatible with the traditional MP in this respect.

__Function:__ void **msqrt** *(MINT * operand, MINT *root, MINT *remainder)*

Set `root` to the square root of `operand`, as with
`mpz_sqrt`

. Set `remainder` to
(i.e. zero if `operand` is a perfect square).

__Function:__ void **pow** *(MINT * base, MINT *exp, MINT *mod, MINT *dest)*

Set `dest` to (`base` raised to `exp`) modulo `mod`.

__Function:__ void **rpow** *(MINT * base, signed short int exp, MINT *dest)*

Set `dest` to `base` raised to `exp`.

__Function:__ void **gcd** *(MINT * operand1, MINT *operand2, MINT *res)*

Set `res` to the greatest common divisor of `operand1` and
`operand2`.

__Function:__ int **mcmp** *(MINT * operand1, MINT *operand2)*

Compare `operand1` and `operand2`. Return a positive value if
`operand1` > `operand2`, zero if `operand1` =
`operand2`, and a negative value if `operand1` < `operand2`.

__Function:__ void **min** *(MINT * dest)*

Input a decimal string from stdin, and put the read integer in
`dest`. SPC and TAB are allowed in the number string, and are
ignored.

__Function:__ void **mout** *(MINT * src)*

Output `src` to stdout, as a decimal string. Also output a newline.

__Function:__ char * **mtox** *(MINT * operand)*

Convert `operand` to a hexadecimal string, and return a pointer to
the string. The returned string is allocated using the default memory
allocation function, `malloc`

by default. (See section Initialization,
for an explanation of the memory allocation in MP).

__Function:__ void **mfree** *(MINT * operand)*

De-allocate, the space used by `operand`. **This function
should only be passed a value returned by itom or xtom.**

Go to the previous, next section.