[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 1

## madd, msub, mult, mdiv, pow, gcd, invert, rpow, msqrt, mcmp, move, min, omin, fmin, m_in, mout, omout, fmout, m_out, sdiv, or itom Subroutine

### Purpose

Multiple-precision integer arithmetic.

### Library

Berkeley Compatibility Library (libbsd.a)

### Syntax

```#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)`

### Description

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.

### Parameters

 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 Codes

Error messages and core images are displayed as a result of illegal operations and running out of memory.

### Implementation Specifics

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.

### Files

 /usr/lib/libbsd.a Object code library.

### Related Information

The bc command, dc command.

Subroutines Overview in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.

[ Previous | Next | Contents | Glossary | Home | Search ]