Commit | Line | Data |
---|---|---|
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 | .\" | |
290bb94a | 5 | .\" @(#)mp.3 6.4 (Berkeley) %G% |
18a639b1 | 6 | .\" |
290bb94a KM |
7 | .TH MP 3X "" |
8 | .UC 6 | |
0596d795 | 9 | .SH NAME |
18a639b1 DS |
10 | madd, msub, mult, mdiv, pow, gcd, invert, rpow, msqrt, mcmp, |
11 | move, 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 |
50 | These routines perform arithmetic on integers of | |
51 | arbitrary length. | |
52 | The integers are stored using the defined type | |
53 | .IR MINT . | |
18a639b1 | 54 | Pointers to a |
0596d795 DS |
55 | .I MINT |
56 | can be initialized using the function | |
57 | .I itom | |
58 | which sets the initial value to | |
59 | .IR n . | |
d8ac6eb3 | 60 | After that, space is managed automatically by the routines. |
0596d795 | 61 | .PP |
18a639b1 DS |
62 | .IR madd , " msub " and " mult" |
63 | assign to | |
64 | .I c | |
65 | the sum, difference and | |
66 | product, respectively, of | |
67 | .IR a " and " b . | |
0596d795 | 68 | .I mdiv |
18a639b1 DS |
69 | assigns to |
70 | .IR q " and " r | |
71 | the quotient and remainder obtained | |
72 | from dividing | |
73 | .IR a " by " b. | |
0596d795 DS |
74 | .I sdiv |
75 | is like | |
76 | .I mdiv | |
18a639b1 DS |
77 | except that the divisor is a short integer |
78 | .I n | |
79 | and the remainder is placed in a short | |
80 | whose address is given as | |
81 | .IR r . | |
0596d795 | 82 | .I msqrt |
18a639b1 DS |
83 | produces the integer square root of |
84 | .IR a " in " b | |
85 | and places the remainder in | |
86 | .IR r . | |
0596d795 | 87 | .I rpow |
18a639b1 DS |
88 | calculates in |
89 | .I c | |
90 | the value of | |
0596d795 DS |
91 | .I a |
92 | raised to the (``regular'' integral) power | |
93 | .IR n , | |
94 | while | |
95 | .I pow | |
18a639b1 DS |
96 | calculates this with a full multiple precision exponent |
97 | .I b | |
98 | and the result is reduced modulo | |
0596d795 | 99 | .IR m . |
18a639b1 DS |
100 | .I gcd |
101 | returns the greatest common denominator of | |
102 | .IR a " and " b " in " c , | |
103 | and | |
104 | .I invert | |
105 | computes | |
106 | .IR c " such that " a*c " mod " b " = 1," | |
107 | for | |
108 | .IR a " and " b | |
109 | relatively prime. | |
110 | .I mcmp | |
111 | returns a negative, zero or positive integer value when | |
112 | .I a | |
113 | is less than, equal to or greater than | |
114 | .IR b , | |
115 | respectively. | |
116 | .I move | |
117 | copies | |
118 | .IR a " to " b . | |
0596d795 | 119 | .IR min " and " mout |
18a639b1 DS |
120 | do decimal input and output while |
121 | .IR omin " and " omout | |
122 | do octal input and output. | |
0596d795 DS |
123 | More generally, |
124 | .IR fmin " and " fmout | |
18a639b1 | 125 | do decimal input and output using file |
0596d795 DS |
126 | .IR f , |
127 | and | |
128 | .IR m_in " and " m_out | |
18a639b1 | 129 | do I/O with arbitrary radix |
0596d795 | 130 | .IR n . |
18a639b1 DS |
131 | On input, records should have the form of |
132 | strings of digits terminated by a newline; | |
133 | output records have a similar form. | |
0596d795 | 134 | .PP |
18a639b1 DS |
135 | Programs which use the multiple-precision arithmetic library |
136 | must 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 | 144 | dc(1), bc(1) |
0596d795 DS |
145 | .SH DIAGNOSTICS |
146 | Illegal operations and running out of memory | |
147 | produce messages and core images. | |
148 | .SH BUGS | |
149 | Bases for input and output should be <= 10. | |
150 | .PP | |
18a639b1 DS |
151 | .IR dc (1) |
152 | and | |
153 | .IR bc (1) | |
154 | don't use this library. | |
155 | .PP | |
156 | The input and output routines are a crock. | |
157 | .PP | |
158 | .I pow | |
159 | is also the name of a standard math library routine. |