manpagez: man pages & more
info gmp
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13 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 section 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’.

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, null-terminated 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 unless it is zero.

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

Function: void msqrt (MINT *op, MINT *root, MINT *remainder)

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.

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

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

Note that the name pow clashes with pow from the standard C math library (see Exponentiation and Logarithms in The GNU C Library Reference Manual). An application will only be able to use one or the other.

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

Set dest to base raised to exp.

Function: void gcd (MINT *op1, MINT *op2, MINT *res)

Set res to the greatest common divisor of op1 and op2.

Function: int mcmp (MINT *op1, MINT *op2)

Compare op1 and op2. Return a positive value if op1 > op2, zero if op1 = op2, and a negative value if op1 < op2.

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 *op)

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.

Function: void mfree (MINT *op)

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


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on February 16, 2012 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.