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"
31 .\" See above for rationale for this date.
37 .Nd traditional BSD multiple precision integer arithmetic library
41 Function prototypes are given in the main body of the text.
43 Applications using this interface must be linked with
51 This interface is obsolete in favor of the
60 multiple precision integer arithmetic library.
61 It has a number of problems,
62 and is unsuitable for use in any programs where reliability is a concern.
63 It is provided here for compatibility only.
65 These routines perform arithmetic on integers of arbitrary precision
66 stored using the defined type
74 and must be recycled with
76 when they are no longer needed.
77 Routines which store a result in one of their arguments expect that
78 the latter has also been initialized prior to being passed to it.
79 The following routines are defined and implemented:
82 .Fn mp_itom "short n" ;
85 .Fn mp_xtom "const char *s" ;
88 .Fn mp_mtox "const MINT *mp" ;
91 .Fn mp_mfree "MINT *mp" ;
92 .Bd -ragged -offset indent
103 which is treated to be in hexadecimal.
104 The return values from
108 must be released with
110 when they are no longer needed.
112 returns a null-terminated hexadecimal string having the value of
114 its return value must be released with
117 when it is no longer needed.
121 .Fn mp_madd "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ;
124 .Fn mp_msub "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ;
127 .Fn mp_mult "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ;
128 .Bd -ragged -offset indent
133 store the sum, difference, or product, respectively, of
142 .Fn mp_mdiv "const MINT *nmp" "const MINT *dmp" "MINT *qmp" "MINT *rmp" ;
145 .Fn mp_sdiv "const MINT *nmp" "short d" "MINT *qmp" "short *ro" ;
146 .Bd -ragged -offset indent
148 computes the quotient and remainder of
152 and stores the result in
168 are ordinary integers.
172 .Fn mp_pow "const MINT *bmp" "const MINT *emp" "const MINT *mmp" "MINT *rmp" ;
175 .Fn mp_rpow "const MINT *bmp" "short e" "MINT *rmp" ;
176 .Bd -ragged -offset indent
178 computes the result of
182 power and reduced modulo
184 the result is stored in
187 computes the result of
191 power and stores the result in
196 .Fn mp_min "MINT *mp" ;
199 .Fn mp_mout "const MINT *mp" ;
200 .Bd -ragged -offset indent
202 reads a line from standard input, tries to interpret it as a decimal
203 number, and if successful, stores the result in
206 prints the value, in decimal, of
208 to standard output (without a trailing newline).
212 .Fn mp_gcd "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ;
213 .Bd -ragged -offset indent
215 computes the greatest common divisor of
219 and stores the result in
224 .Fn mp_mcmp "const MINT *mp1" "const MINT *mp2" ;
225 .Bd -ragged -offset indent
227 compares the values of
232 0 if the two values are equal,
233 a value greater than 0 if
237 and a value less than 0 if
244 .Fn mp_move "const MINT *smp" "MINT *tmp" ;
245 .Bd -ragged -offset indent
251 (both values must be initialized).
255 .Fn mp_msqrt "const MINT *nmp" "MINT *xmp" "MINT *rmp" ;
256 .Bd -ragged -offset indent
258 computes the square root and remainder of
266 .Sh IMPLEMENTATION NOTES
269 is implemented in terms of the
274 Running out of memory or illegal operations result in error messages
275 on standard error and a call to
292 implemented in terms of
294 This implementation appeared in
297 Errors are reported via output to standard error and abnormal
298 program termination instead of via return values.
299 The application cannot control this behavior.
301 It is not clear whether the string returned by
303 may be written to by the caller.
304 This implementation allows it, but others may not.
307 would take a pointer to a buffer to fill in.
309 It is not clear whether using the same variable as both source and
310 destination in a single invocation is permitted.
311 Some of the calls in this implementation allow this, while others