Multiple-precision integer arithmetic.
Berkeley Compatibility Library (libbsd.a)
#include <mp.h>
#include <stdio.h>
typedef struct mint {int Length; short * Value} MINT;
madd( a, b, c)
msub(a,b,c)
mult(a,b,c)
mdiv(a,b, q, r)
pow(a,b, m,c)
gcd(a,b,c)
invert(a,b,c)
rpow(a,n,c)
msqrt(a,b,r)
mcmp(a,b)
move(a,b)
min(a)
omin(a)
fmin(a,f)
m_in(a, n,f)
mout(a)
omout(a)
fmout(a,f)
m_out(a,n,f)
MINT *a, *b, *c, *m, *q, *r;
FILE * f;
int n;
sdiv(a,n,q,r)
MINT *a, *q;
short n;
short *r;
MINT *itom(n)
These subroutines perform arithmetic on integers of arbitrary Length. The integers are stored using the defined type MINT. Pointers to a MINT can be initialized using the itom subroutine, which sets the initial Value to n. After that, space is managed automatically by the subroutines.
The madd subroutine, msub subroutine, and mult subroutine assign to c the sum, difference, and product, respectively, of a and b.
The mdiv subroutine assigns to q and r the quotient and remainder obtained from dividing a by b.
The sdiv subroutine is like the mdiv subroutine except that the divisor is a short integer n and the remainder is placed in a short whose address is given as r.
The msqrt subroutine produces the integer square root of a in b and places the remainder in r.
The rpow subroutine calculates in c the value of a raised to the (regular integral) power n, while the pow subroutine calculates this with a full multiple precision exponent b and the result is reduced modulo m.
The gcd subroutine returns the greatest common denominator of a and b in c, and the invert subroutine computes c such that a*c mod b=1, for a and b relatively prime.
The mcmp subroutine returns a negative, 0, or positive integer value when a is less than, equal to, or greater than b, respectively.
The move subroutine copies a to b. The min subroutine and mout subroutine do decimal input and output while the omin subroutine and omout subroutine do octal input and output. More generally, the fmin subroutine and fmout subroutine do decimal input and output using file f, and the m_in subroutine and m_out subroutine do inputs and outputs with arbitrary radix n. On input, records should have the form of strings of digits terminated by a new line; output records have a similar form.
Programs that use the multiple-precision arithmetic functions must link with the libbsd.a library.
Bases for input and output should be less than or equal to 10.
pow is also the name of a standard math library routine.
Item | Description |
---|---|
Length | Specifies the length of an integer. |
Value | Specifies the initial value to be used in the routine. |
a | Specifies the first operand of the multiple-precision routines. |
b | Specifies the second operand of the multiple-precision routines. |
c | Contains the integer result. |
f | A pointer of the type FILE that points to input and output files used with input/output routines. |
m | Indicates modulo. |
n | Provides a value used to specify radix with m_in and m_out, power with rpow, and divisor with sdiv. |
q | Contains the quotient obtained from mdiv. |
r | Contains the remainder obtained from mdiv, sdiv, and msqrt. |
Error messages and core images are displayed as a result of illegal operations and running out of memory.
Item | Description |
---|---|
/usr/lib/libbsd.a | Object code library. |