xref: /original-bsd/lib/libmp/mp.3 (revision c3e32dec)
1.\" Copyright (c) 1986, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.proprietary.roff%
5.\"
6.\"	@(#)mp.3	8.1 (Berkeley) 06/04/93
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
61The interface for this library is expected to change.
62.Ef
63.Pp
64These functions operate on integers of variable length.
65The function
66.Fn itom
67allocates space for an integer of length
68.Fa n
69which may be accessed via the returned
70.Fa MINT
71pointer.
72The underlying storage scheme is transparent to the user.
73.Pp
74.Bl -tag -width "mdivXXX" -compact
75.It Fn fmin
76.It Fn fmout
77Convert decimal input and output using file
78.Fa f .
79.Pp
80.It Fn gcd
81Finds the greatest common denominator of
82.Fa a
83and
84.Fa b ,
85storing the result
86in
87.Fa c .
88.Pp
89.It Fn invert
90Computes
91.Fa c
92such that
93.Fa a Ns * Fa c No mod
94.Fa b
95= 1,
96for
97.Fa a
98and
99.Fa b
100relatively prime.
101.Pp
102.It Fn m_in
103.It Fn m_out
104.Tn I/O
105with arbitrary radix
106.Fa n .
107.Pp
108.It Fn madd
109The sum of
110.Fa a
111and
112.Fa b
113is stored in
114.Fa c .
115.Pp
116.It Fn mcmp
117Returns a negative, zero or positive integer value when
118.Fa a
119is less than, equal to or greater than
120.Fa b ,
121respectively.
122.It Fn move
123Copies
124.Fa a
125to
126.Fa b .
127.Pp
128.It Fn min
129.It Fn mout
130Convert decimal input and output.
131.Pp
132.It Fn mdiv
133Divides
134.Fa a
135by
136.Fa b
137and stores the quotient in
138.Fa q
139and the remainder in
140.Fa r .
141.Pp
142.It Fn msqrt
143Calculates the integer square root of
144.Fa a
145in
146.Fa b
147and places the remainder in
148.Fa r .
149.Pp
150.It Fn msub
151The difference of
152.Fa a
153and
154.Fa b
155is stored in
156.Fa c .
157.Pp
158.It Fn mult
159The product of
160.Fa a
161and
162.Fa b
163is stored in
164.Fa c .
165.Pp
166.It Fn omin
167.It Fn omout
168Convert octal input and output.
169.Pp
170.It Fn pow
171Calculates
172the value of
173.Fa a
174raised to the
175full multiple precision exponent
176.Fa b ,
177the result is reduced modulo
178.Fa m
179and stored in
180.Fa c .
181.Pp
182.It Fn rpow
183Calculates
184the value of
185.Fa a
186raised to the (``regular'' integral) power
187.Fa n
188and stores the result in
189.Fa c .
190.Pp
191.It Fn sdiv
192(Short divisor.)
193Divides
194.Fa a
195by the short integer
196.Fa b
197and stores the quotient in
198.Fa q
199and the remainder in short integer
200.Fa r .
201On input, records should have the form of
202strings of digits terminated by a newline;
203output records have a similar form.
204.El
205.Sh FILES
206.Bl -tag -width /usr/include/mp.h -compact
207.It Pa /usr/lib/libmp.a
208object code library
209.It Pa /usr/include/mp.h
210include file
211.El
212.Sh SEE ALSO
213.Xr dc 1 ,
214.Xr bc 1
215.Sh HISTORY
216A
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 ,
228and
229.Fn sdiv
230function appeared in
231.At v7 .
232.\" The rest of the functions appeared in
233.\" .Bx ??
234.Sh BUGS
235Bases for input and output should be <= 10.
236.Pp
237The interpreters
238.Xr dc 1
239and
240.Xr bc 1
241don't use this library.
242.Pp
243The input and output routines are a crock.
244.Pp
245The function name
246.Fn pow
247is also the name of a standard math library routine.
248