Commit | Line | Data |
---|---|---|
a493d448 | 1 | .\" Copyright (c) 1986, 1991 The Regents of the University of California. |
ae59e04c | 2 | .\" All rights reserved. |
18a639b1 | 3 | .\" |
a493d448 | 4 | .\" %sccs.include.proprietary.roff% |
18a639b1 | 5 | .\" |
a493d448 | 6 | .\" @(#)mp.3 6.6 (Berkeley) %G% |
ae59e04c CL |
7 | .\" |
8 | .Dd | |
9 | .Dt MP 3 | |
10 | .Os BSD 4.3 | |
11 | .Sh NAME | |
12 | .Nm fmin , | |
13 | .Nm fmout , | |
14 | .Nm gcd , | |
15 | .Nm invert , | |
16 | .Nm itom | |
17 | .Nm m_in , | |
18 | .Nm m_out , | |
19 | .Nm madd , | |
20 | .Nm mcmp, | |
21 | .Nm mdiv , | |
22 | .Nm min , | |
23 | .Nm mout , | |
24 | .Nm move , | |
25 | .Nm msqrt , | |
26 | .Nm msub , | |
27 | .Nm mult , | |
28 | .Nm omin , | |
29 | .Nm omout , | |
30 | .Nm pow , | |
31 | .Nm rpow , | |
32 | .Nm sdiv , | |
33 | .Nd multiple precision integer arithmetic | |
34 | .Sh SYNOPSIS | |
35 | .Fd #include <mp.h> | |
36 | .Fd #include <stdio.h> | |
37 | .Fd "typedef struct mint { int len; short *val; } MINT;" | |
38 | .Fn madd "MINT *a" "MINT *b" "MINT *c" | |
39 | .Fn msub "MINT *a" "MINT *b" "MINT *c" | |
40 | .Fn mult "MINT *a" "MINT *b" "MINT *c" | |
41 | .Fn mdiv "MINT *a" "MINT *b" "MINT *q" "short r" | |
42 | .Fn pow "MINT *a" "MINT *b" m "MINT *c" | |
43 | .Fn gcd "MINT *a" "MINT *b" "MINT *c" | |
44 | .Fn invert "MINT *a" "MINT *b" "MINT *c" | |
45 | .Fn rpow "MINT *a" "short n" "MINT *c" | |
46 | .Fn msqrt "MINT *a" "MINT *b" "short r" | |
47 | .Fn mcmp "MINT *a" "MINT *b" | |
48 | .Fn move "MINT *a" "MINT *b" | |
49 | .Fn min "MINT *a" | |
50 | .Fn omin "MINT *a" | |
51 | .Fn fmin "MINT *a" "FILE *f" | |
52 | .Fn m_in "MINT *a" "int n" "FILE *f" | |
53 | .Fn mout "MINT *a" | |
54 | .Fn omout "MINT *a" | |
55 | .Fn fmout "MINT *a" "FILE *f" | |
56 | .Fn m_out "MINT *a" "int n" "FILE *f" | |
57 | .Fn sdiv "MINT *a" "short n" "MINT *q" "short r" | |
58 | .Fn itom "short n" | |
59 | .Sh DESCRIPTION | |
60 | .Bf -symbolic | |
61 | The interface for this library is expected to change. | |
62 | .Ef | |
63 | .Pp | |
64 | These functions operate on integers of variable length. | |
65 | The function | |
66 | .Fn itom | |
67 | allocates space for an integer of length | |
68 | .Fa n | |
69 | which may be accessed via the returned | |
70 | .Fa MINT | |
71 | pointer. | |
72 | The underlying storage scheme is transparent to the user. | |
73 | .Pp | |
74 | .Bl -tag -width "mdivXXX" -compact | |
75 | .It Fn fmin | |
76 | .It Fn fmout | |
77 | Convert decimal input and output using file | |
78 | .Fa f . | |
79 | .Pp | |
80 | .It Fn gcd | |
81 | Finds the greatest common denominator of | |
82 | .Fa a | |
18a639b1 | 83 | and |
ae59e04c CL |
84 | .Fa b , |
85 | storing the result | |
86 | in | |
87 | .Fa c . | |
88 | .Pp | |
89 | .It Fn invert | |
90 | Computes | |
91 | .Fa c | |
92 | such that | |
93 | .Fa a Ns * Fa c No mod | |
94 | .Fa b | |
95 | = 1, | |
18a639b1 | 96 | for |
ae59e04c CL |
97 | .Fa a |
98 | and | |
99 | .Fa b | |
18a639b1 | 100 | relatively prime. |
ae59e04c CL |
101 | .Pp |
102 | .It Fn m_in | |
103 | .It Fn m_out | |
104 | .Tn I/O | |
105 | with arbitrary radix | |
106 | .Fa n . | |
107 | .Pp | |
108 | .It Fn madd | |
109 | The sum of | |
110 | .Fa a | |
111 | and | |
112 | .Fa b | |
113 | is stored in | |
114 | .Fa c . | |
115 | .Pp | |
116 | .It Fn mcmp | |
117 | Returns a negative, zero or positive integer value when | |
118 | .Fa a | |
18a639b1 | 119 | is less than, equal to or greater than |
ae59e04c | 120 | .Fa b , |
18a639b1 | 121 | respectively. |
ae59e04c CL |
122 | .It Fn move |
123 | Copies | |
124 | .Fa a | |
125 | to | |
126 | .Fa b . | |
127 | .Pp | |
128 | .It Fn min | |
129 | .It Fn mout | |
130 | Convert decimal input and output. | |
131 | .Pp | |
132 | .It Fn mdiv | |
133 | Divides | |
134 | .Fa a | |
135 | by | |
136 | .Fa b | |
137 | and stores the quotient in | |
138 | .Fa q | |
139 | and the remainder in | |
140 | .Fa r . | |
141 | .Pp | |
142 | .It Fn msqrt | |
143 | Calculates the integer square root of | |
144 | .Fa a | |
145 | in | |
146 | .Fa b | |
147 | and places the remainder in | |
148 | .Fa r . | |
149 | .Pp | |
150 | .It Fn msub | |
151 | The difference of | |
152 | .Fa a | |
153 | and | |
154 | .Fa b | |
155 | is stored in | |
156 | .Fa c . | |
157 | .Pp | |
158 | .It Fn mult | |
159 | The product of | |
160 | .Fa a | |
0596d795 | 161 | and |
ae59e04c CL |
162 | .Fa b |
163 | is stored in | |
164 | .Fa c . | |
165 | .Pp | |
166 | .It Fn omin | |
167 | .It Fn omout | |
168 | Convert octal input and output. | |
169 | .Pp | |
170 | .It Fn pow | |
171 | Calculates | |
172 | the value of | |
173 | .Fa a | |
174 | raised to the | |
175 | full multiple precision exponent | |
176 | .Fa b , | |
177 | the result is reduced modulo | |
178 | .Fa m | |
179 | and stored in | |
180 | .Fa c . | |
181 | .Pp | |
182 | .It Fn rpow | |
183 | Calculates | |
184 | the value of | |
185 | .Fa a | |
186 | raised to the (``regular'' integral) power | |
187 | .Fa n | |
188 | and stores the result in | |
189 | .Fa c . | |
190 | .Pp | |
191 | .It Fn sdiv | |
192 | (Short divisor.) | |
193 | Divides | |
194 | .Fa a | |
195 | by the short integer | |
196 | .Fa b | |
197 | and stores the quotient in | |
198 | .Fa q | |
199 | and the remainder in short integer | |
200 | .Fa r . | |
18a639b1 DS |
201 | On input, records should have the form of |
202 | strings of digits terminated by a newline; | |
203 | output records have a similar form. | |
ae59e04c CL |
204 | .El |
205 | .Sh FILES | |
206 | .Bl -tag -width /usr/include/mp.h -compact | |
207 | .It Pa /usr/lib/libmp.a | |
208 | object code library | |
209 | .It Pa /usr/include/mp.h | |
210 | include file | |
211 | .El | |
212 | .Sh SEE ALSO | |
213 | .Xr dc 1 , | |
214 | .Xr bc 1 | |
215 | .Sh HISTORY | |
216 | A | |
217 | .Fn gcd , | |
218 | .Fn itom , | |
219 | .Fn madd , | |
220 | .Fn mdiv , | |
221 | .Fn min , | |
222 | .Fn mout , | |
223 | .Fn msqrt , | |
224 | .Fn msub , | |
225 | .Fn mult , | |
226 | .Fn pow , | |
227 | .Fn rpow , | |
228 | and | |
229 | .Fn sdiv | |
230 | function appeared in | |
231 | .At v7 . | |
232 | .\" The rest of the functions appeared in | |
233 | .\" .Bx ?? | |
234 | .Sh BUGS | |
0596d795 | 235 | Bases for input and output should be <= 10. |
ae59e04c CL |
236 | .Pp |
237 | The interpreters | |
238 | .Xr dc 1 | |
18a639b1 | 239 | and |
ae59e04c | 240 | .Xr bc 1 |
18a639b1 | 241 | don't use this library. |
ae59e04c | 242 | .Pp |
18a639b1 | 243 | The input and output routines are a crock. |
ae59e04c CL |
244 | .Pp |
245 | The function name | |
246 | .Fn pow | |
18a639b1 | 247 | is also the name of a standard math library routine. |