install C version of _doprnt
[unix-history] / usr / src / lib / libmp / mp.3
... / ...
CommitLineData
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.4 (Berkeley) %G%
6.\"
7.TH MP 3X ""
8.UC 6
9.SH NAME
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
13.SH SYNOPSIS
14.nf
15.B #include <mp.h>
16.B #include <stdio.h>
17.PP
18.B "typedef struct mint { int len; short *val; } MINT;"
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)
24.B pow(a, b, m, c)
25.B gcd(a, b, c)
26.B invert(a, b, c)
27.B rpow(a, n, c)
28.B msqrt(a, b, r)
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)
39.B MINT *a, *b, *c, *m, "*q, *r;"
40.B FILE *f;
41.B int n;
42.PP
43.B sdiv(a, n, q, r)
44.B MINT *a, *q;
45.B short n;
46.B short *r;
47.PP
48.B MINT *itom(n)
49.SH DESCRIPTION
50These routines perform arithmetic on integers of
51arbitrary length.
52The integers are stored using the defined type
53.IR MINT .
54Pointers to a
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
62.IR madd , " msub " and " mult"
63assign to
64.I c
65the sum, difference and
66product, respectively, of
67.IR a " and " b .
68.I mdiv
69assigns to
70.IR q " and " r
71the quotient and remainder obtained
72from dividing
73.IR a " by " b.
74.I sdiv
75is like
76.I mdiv
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 .
82.I msqrt
83produces the integer square root of
84.IR a " in " b
85and places the remainder in
86.IR r .
87.I rpow
88calculates in
89.I c
90the value of
91.I a
92raised to the (``regular'' integral) power
93.IR n ,
94while
95.I pow
96calculates this with a full multiple precision exponent
97.I b
98and the result is reduced modulo
99.IR m .
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 .
119.IR min " and " mout
120do decimal input and output while
121.IR omin " and " omout
122do octal input and output.
123More generally,
124.IR fmin " and " fmout
125do decimal input and output using file
126.IR f ,
127and
128.IR m_in " and " m_out
129do I/O with arbitrary radix
130.IR n .
131On input, records should have the form of
132strings of digits terminated by a newline;
133output records have a similar form.
134.PP
135Programs which use the multiple-precision arithmetic library
136must be loaded using the loader flag
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
144dc(1), bc(1)
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
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.