This version handles out-of-band data, abort output, and
[unix-history] / usr / src / lib / libmp / mp.3
CommitLineData
18a639b1
DS
1.\" Copyright (c) 1986 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)mp.3 6.2 (Berkeley) %G%
6.\"
0596d795
DS
7.TH MP 3X
8.UC
9.SH NAME
18a639b1
DS
10madd, msub, mult, mdiv, pow, gcd, invert, rpow, msqrt, mcmp,
11move, min, omin, fmin, m_in, mout, omout, fmout, m_out, sdiv, itom
12\- multiple precision integer arithmetic
0596d795
DS
13.SH SYNOPSIS
14.nf
15.B #include <mp.h>
18a639b1 16.B #include <stdio.h>
0596d795 17.PP
18a639b1 18.B "typedef struct mint { int len; short *val; } MINT;"
0596d795
DS
19.PP
20.B madd(a, b, c)
21.B msub(a, b, c)
22.B mult(a, b, c)
23.B mdiv(a, b, q, r)
0596d795
DS
24.B pow(a, b, m, c)
25.B gcd(a, b, c)
18a639b1 26.B invert(a, b, c)
0596d795
DS
27.B rpow(a, n, c)
28.B msqrt(a, b, r)
18a639b1
DS
29.B mcmp(a, b)
30.B move(a, b)
31.B min(a)
32.B omin(a)
33.B fmin(a, f)
34.B m_in(a, n, f)
35.B mout(a)
36.B omout(a)
37.B fmout(a, f)
38.B m_out(a, n, f)
0596d795 39.B MINT *a, *b, *c, *m, "*q, *r;"
18a639b1 40.B FILE *f;
0596d795
DS
41.B int n;
42.PP
0596d795
DS
43.B sdiv(a, n, q, r)
44.B MINT *a, *q;
18a639b1 45.B short n;
0596d795
DS
46.B short *r;
47.PP
48.B MINT *itom(n)
0596d795
DS
49.SH DESCRIPTION
50These routines perform arithmetic on integers of
51arbitrary length.
52The integers are stored using the defined type
53.IR MINT .
18a639b1 54Pointers to a
0596d795
DS
55.I MINT
56can be initialized using the function
57.I itom
58which sets the initial value to
59.IR n .
60After that space is managed automatically by the routines.
61.PP
18a639b1
DS
62.IR madd , " msub " and " mult"
63assign to
64.I c
65the sum, difference and
66product, respectively, of
67.IR a " and " b .
0596d795 68.I mdiv
18a639b1
DS
69assigns to
70.IR q " and " r
71the quotient and remainder obtained
72from dividing
73.IR a " by " b.
0596d795
DS
74.I sdiv
75is like
76.I mdiv
18a639b1
DS
77except that the divisor is a short integer
78.I n
79and the remainder is placed in a short
80whose address is given as
81.IR r .
0596d795 82.I msqrt
18a639b1
DS
83produces the integer square root of
84.IR a " in " b
85and places the remainder in
86.IR r .
0596d795 87.I rpow
18a639b1
DS
88calculates in
89.I c
90the value of
0596d795
DS
91.I a
92raised to the (``regular'' integral) power
93.IR n ,
94while
95.I pow
18a639b1
DS
96calculates this with a full multiple precision exponent
97.I b
98and the result is reduced modulo
0596d795 99.IR m .
18a639b1
DS
100.I gcd
101returns the greatest common denominator of
102.IR a " and " b " in " c ,
103and
104.I invert
105computes
106.IR c " such that " a*c " mod " b " = 1,"
107for
108.IR a " and " b
109relatively prime.
110.I mcmp
111returns a negative, zero or positive integer value when
112.I a
113is less than, equal to or greater than
114.IR b ,
115respectively.
116.I move
117copies
118.IR a " to " b .
0596d795 119.IR min " and " mout
18a639b1
DS
120do decimal input and output while
121.IR omin " and " omout
122do octal input and output.
0596d795
DS
123More generally,
124.IR fmin " and " fmout
18a639b1 125do decimal input and output using file
0596d795
DS
126.IR f ,
127and
128.IR m_in " and " m_out
18a639b1 129do I/O with arbitrary radix
0596d795 130.IR n .
18a639b1
DS
131On input, records should have the form of
132strings of digits terminated by a newline;
133output records have a similar form.
0596d795 134.PP
18a639b1
DS
135Programs which use the multiple-precision arithmetic library
136must be loaded using the loader flag
0596d795
DS
137.IR \-lmp .
138.SH FILES
139.ta 2i
140/usr/include/mp.h include file
141.br
142/usr/lib/libmp.a object code library
143.SH SEE ALSO
18a639b1 144dc(1), bc(1)
0596d795
DS
145.SH DIAGNOSTICS
146Illegal operations and running out of memory
147produce messages and core images.
148.SH BUGS
149Bases for input and output should be <= 10.
150.PP
18a639b1
DS
151.IR dc (1)
152and
153.IR bc (1)
154don't use this library.
155.PP
156The input and output routines are a crock.
157.PP
158.I pow
159is also the name of a standard math library routine.