Go forward to Custom Allocation.
Go backward to Low-level Functions.
Go up to 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 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 unless it is zero.
Some implementations of these functions work differently--or not
at all--for negative arguments.
- Function: void msqrt (MINT *OPERAND, MINT *ROOT, MINT *REMAINDER)
Set ROOT to the truncated integer part of the square root of
OPERAND. Set REMAINDER to OPERAND-ROOT*ROOT, (i.e., zero if
OPERAND 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.
- 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.
- 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'.*