1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
.TH MP 3X
.CT 2 math
.SH NAME
itom, mfree, madd, msub, mult, mdiv, sdiv, msqrt, mgcd, min, mout,
fmin, fmout, move, mcmp,
rpow, mpow \(mi multiple precision integer arithmetic
.SH SYNOPSIS
.nf
.2C
.B "#include <mp.h>"
.B "#include <stdio.h>"
.PP
.B mint *itom(n)
.B short n;
.PP
.B mfree(a)
.B mint *a;
.PP
.B madd(a, b, c)
.B mint *a, *b, *c;
.PP
.B msub(a, b, c)
.B mint *a, *b, *c;
.PP
.B mult(a, b, c)
.B mint *a, *b, *c;
.PP
.B mgcd(a, b, c)
.B mint *a, *b, *c;
.PP
.B mdiv(a, b, q, r)
.B mint *a, *b, *q, *r;
.PP
.B sdiv(a, n, q, r)
.B mint *a, *q;
.B short n, *r;
.PP
.B \&
.B msqrt(a, b, r)
.B mint *a, *b, *r;
.PP
.B rpow(a, n, c)
.B mint *a, *c;
.PP
.B mpow(a, b, m, c)
.B mint *a, *b, *m, *c;
.PP
.B move(a, b)
.B mint *a, *b;
.PP
.B mcmp(a, b)
.B mint *a, *b;
.PP
.B int min(a)
.B mint *a;
.PP
.B mout(a)
.B mint *a;
.PP
.B int fmin(a, f)
.B mint *a;
.B FILE *f;
.PP
.B fmout(a, f)
.B mint *a;
.B FILE *f;
.1C
.SH DESCRIPTION
These routines perform arithmetic on arbitrary-length integers
of defined type
.I mint.
The functions are obtained with the
.IR ld (1)
option
.BR -lmp .
.PP
Pointers to
.I mint
must be initialized using the function
.IR itom ,
which sets the initial value to
.IR n .
Thereafter space is managed automatically.
The space may be freed by
.IR mfree ,
making the variable uninitialized.
.PP
.I Madd, msub, mult,
and
.I mgcd
assign to their third arguments the sum, difference,
product, and greatest common divisor, respectively, of their first two arguments.
.PP
.I Mdiv
assigns the quotient and remainder, respectively,
to its third and fourth arguments.
The remainder is nonnegative and less than the divisor in magnitude.
.I Sdiv
is like
.I mdiv
except that the divisor is an ordinary integer.
.PP
.I Msqrt
assigns the square root and remainder to its second and third arguments,
respectively.
.PP
.I Rpow
calculates
.I a
raised to the power
.IR n ;
.I mpow
calculates this reduced modulo
.IR m .
.PP
.IR Move
assigns (by copying) the value of its first argument to its second argument.
.PP
.IR Mcmp
returns a negative, zero, or positive integer if the value of its
first argument is less than,
equal to, or greater than, respectively,
the value of its second argument.
.PP
.I Min
and
.I mout
do decimal conversion from
.B stdin
and to
.BR stdout ,
.I fmin
and
.I fmout
use file
.IR f ;
see
.IR stdio (3).
.I Min
and
.I fmin
return
.B EOF
on end of file.
.SH DIAGNOSTICS
Illegal operations and running out of memory
produce messages and core images.
.SH BUGS
.I Itom
and
.I sdiv
fail if
.I n
is the most negative short integer.
|