Node:BSD Compatible Functions, Next:, Previous:C++ Class Interface, Up:Top



Berkeley MP Compatible Functions

These functions are intended to be fully compatible with the Berkeley MP library which is available on many BSD derived U*ix systems. The --enable-mpbsd option must be used when building GNU MP to make these available (see Installing GMP).

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 your 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.

MINT * itom (signed short int initial_value) Function
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.

MINT * xtom (char *initial_value) Function
Allocate an integer consisting of a MINT object and dynamic limb space. Initialize the integer from initial_value, a hexadecimal, null-terminated C string. Return a pointer to the MINT object.

void move (MINT *src, MINT *dest) Function
Set dest to src by copying. Both variables must be previously initialized.

void madd (MINT *src_1, MINT *src_2, MINT *destination) Function
Add src_1 and src_2 and put the sum in destination.

void msub (MINT *src_1, MINT *src_2, MINT *destination) Function
Subtract src_2 from src_1 and put the difference in destination.

void mult (MINT *src_1, MINT *src_2, MINT *destination) Function
Multiply src_1 and src_2 and put the product in destination.

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) Function
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 unless it is zero.

Some implementations of these functions work differently--or not at all--for negative arguments.

void msqrt (MINT *op, MINT *root, MINT *remainder) Function
Set root to the truncated integer part of the square root of op, like mpz_sqrt. Set remainder to op-root*root, i.e. zero if op is a perfect square.

If root and remainder are the same variable, the results are undefined.

void pow (MINT *base, MINT *exp, MINT *mod, MINT *dest) Function
Set dest to (base raised to exp) modulo mod.

void rpow (MINT *base, signed short int exp, MINT *dest) Function
Set dest to base raised to exp.

void gcd (MINT *op1, MINT *op2, MINT *res) Function
Set res to the greatest common divisor of op1 and op2.

int mcmp (MINT *op1, MINT *op2) Function
Compare op1 and op2. Return a positive value if op1 > op2, zero if op1 = op2, and a negative value if op1 < op2.

void min (MINT *dest) Function
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.

void mout (MINT *src) Function
Output src to stdout, as a decimal string. Also output a newline.

char * mtox (MINT *op) Function
Convert op 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. It will be strlen(str)+1 bytes, that being exactly enough for the string and null-terminator.

void mfree (MINT *op) Function
De-allocate, the space used by op. This function should only be passed a value returned by itom or xtom.