2 .\" Copyright (c) 2001 Dima Dorfman.
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" This manual page is based on the mp(3X) manual page from Sun Release
27 .\" 4.1, dated 7 September 1989. It's an old, crufty, and relatively ugly
28 .\" manual page, but it does document what appears to be the "traditional"
33 .\" See above for rationale for this date.
39 .Nd traditional BSD multiple precision integer arithmetic library
43 Function prototypes are given in the main body of the text.
45 Applications using this interface must be linked with
53 This interface is obsolete in favor of the
62 multiple precision integer arithmetic library.
63 It has a number of problems,
64 and is unsuitable for use in any programs where reliability is a concern.
65 It is provided here for compatibility only.
67 These routines perform arithmetic on integers of arbitrary precision
68 stored using the defined type
76 and must be recycled with
78 when they are no longer needed.
79 Routines which store a result in one of their arguments expect that
80 the latter has also been initialized prior to being passed to it.
81 The following routines are defined and implemented:
87 .Fn xtom "const char *s" ;
90 .Fn mtox "const MINT *mp" ;
93 .Fn mfree "MINT *mp" ;
94 .Bd -ragged -offset indent
105 which is treated to be in hexadecimal.
106 The return values from
110 must be released with
112 when they are no longer needed.
114 returns a null-terminated hexadecimal string having the value of
116 its return value must be released with
119 when it is no longer needed.
123 .Fn madd "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ;
126 .Fn msub "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ;
129 .Fn mult "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ;
130 .Bd -ragged -offset indent
135 store the sum, difference, or product, respectively, of
144 .Fn mdiv "const MINT *nmp" "const MINT *dmp" "MINT *qmp" "MINT *rmp" ;
147 .Fn sdiv "const MINT *nmp" "short d" "MINT *qmp" "short *ro" ;
148 .Bd -ragged -offset indent
150 computes the quotient and remainder of
154 and stores the result in
170 are ordinary integers.
174 .Fn pow "const MINT *bmp" "const MINT *emp" "const MINT *mmp" "MINT *rmp" ;
177 .Fn rpow "const MINT *bmp" "short e" "MINT *rmp" ;
178 .Bd -ragged -offset indent
180 computes the result of
184 power and reduced modulo
186 the result is stored in
189 computes the result of
193 power and stores the result in
201 .Fn mout "const MINT *mp" ;
202 .Bd -ragged -offset indent
204 reads a line from standard input, tries to interpret it as a decimal
205 number, and if successful, stores the result in
208 prints the value, in decimal, of
210 to standard output (without a trailing newline).
214 .Fn gcd "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ;
215 .Bd -ragged -offset indent
217 computes the greatest common divisor of
221 and stores the result in
226 .Fn mcmp "const MINT *mp1" "const MINT *mp2" ;
227 .Bd -ragged -offset indent
229 compares the values of
234 0 if the two values are equal,
235 a value greater than 0 if
239 and a value less than 0 if
246 .Fn move "const MINT *smp" "MINT *tmp" ;
247 .Bd -ragged -offset indent
253 (both values must be initialized).
257 .Fn msqrt "const MINT *nmp" "MINT *xmp" "MINT *rmp" ;
258 .Bd -ragged -offset indent
260 computes the square root and remainder of
268 .Sh IMPLEMENTATION NOTES
271 is implemented in terms of the
276 Running out of memory or illegal operations result in error messages
277 on standard error and a call to
294 implemented in terms of
296 This implementation appeared in
301 routine exists in both
305 with incompatible semantics.
307 Errors are reported via output to standard error and abnormal
308 program termination instead of via return values.
309 The application cannot control this behavior.
311 It is not clear whether the string returned by
313 may be written to by the caller.
314 This implementation allows it, but others may not.
317 would take a pointer to a buffer to fill in.
319 It is not clear whether using the same variable as both source and
320 destination in a single invocation is permitted.
321 Some of the calls in this implementation allow this, while others