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.
Note: The pow subroutine is also present in the IEEE Math Library, libm.a, and the System V Math Library, libmsaa.a. The pow subroutine in libm.a or libmsaa.a may be loaded in error unless the libbsd.a library is listed before the libm.a or libmsaa.a library on the command line.
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.
Error messages and core images are displayed as a result of illegal operations and running out of memory.
These subroutines are part of Base Operating System (BOS) Runtime.
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.
/usr/lib/libbsd.a | Object code library. |
Subroutines Overview in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.