libmp.3 (119567) | libmp.3 (189092) |
---|---|
1.\" 2.\" Copyright (c) 2001 Dima Dorfman. 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright --- 14 unchanged lines hidden (view full) --- 23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24.\" SUCH DAMAGE. 25.\" 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" 29.\" libmp interface. 30.\" | 1.\" 2.\" Copyright (c) 2001 Dima Dorfman. 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright --- 14 unchanged lines hidden (view full) --- 23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24.\" SUCH DAMAGE. 25.\" 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" 29.\" libmp interface. 30.\" |
31.\" $FreeBSD: head/lib/libmp/libmp.3 119567 2003-08-30 05:35:46Z seanc $ | 31.\" $FreeBSD: head/lib/libmp/libmp.3 189092 2009-02-26 21:43:15Z ed $ |
32.\" 33.\" See above for rationale for this date. 34.Dd September 7, 1989 35.Dt LIBMP 3 36.Os 37.Sh NAME 38.Nm libmp 39.Nd traditional BSD multiple precision integer arithmetic library --- 25 unchanged lines hidden (view full) --- 65It is provided here for compatibility only. 66.Pp 67These routines perform arithmetic on integers of arbitrary precision 68stored using the defined type 69.Vt MINT . 70Pointers to 71.Vt MINT 72are initialized using | 32.\" 33.\" See above for rationale for this date. 34.Dd September 7, 1989 35.Dt LIBMP 3 36.Os 37.Sh NAME 38.Nm libmp 39.Nd traditional BSD multiple precision integer arithmetic library --- 25 unchanged lines hidden (view full) --- 65It is provided here for compatibility only. 66.Pp 67These routines perform arithmetic on integers of arbitrary precision 68stored using the defined type 69.Vt MINT . 70Pointers to 71.Vt MINT 72are initialized using |
73.Fn itom | 73.Fn mp_itom |
74or | 74or |
75.Fn xtom , | 75.Fn mp_xtom , |
76and must be recycled with | 76and must be recycled with |
77.Fn mfree | 77.Fn mp_mfree |
78when they are no longer needed. 79Routines which store a result in one of their arguments expect that 80the latter has also been initialized prior to being passed to it. 81The following routines are defined and implemented: 82.Pp 83.Ft "MINT *" Ns | 78when they are no longer needed. 79Routines which store a result in one of their arguments expect that 80the latter has also been initialized prior to being passed to it. 81The following routines are defined and implemented: 82.Pp 83.Ft "MINT *" Ns |
84.Fn itom "short n" ; | 84.Fn mp_itom "short n" ; |
85.Pp 86.Ft "MINT *" Ns | 85.Pp 86.Ft "MINT *" Ns |
87.Fn xtom "const char *s" ; | 87.Fn mp_xtom "const char *s" ; |
88.Pp 89.Ft "char *" Ns | 88.Pp 89.Ft "char *" Ns |
90.Fn mtox "const MINT *mp" ; | 90.Fn mp_mtox "const MINT *mp" ; |
91.Pp 92.Ft void | 91.Pp 92.Ft void |
93.Fn mfree "MINT *mp" ; | 93.Fn mp_mfree "MINT *mp" ; |
94.Bd -ragged -offset indent | 94.Bd -ragged -offset indent |
95.Fn itom | 95.Fn mp_itom |
96returns an 97.Vt MINT 98with the value of 99.Fa n . | 96returns an 97.Vt MINT 98with the value of 99.Fa n . |
100.Fn xtom | 100.Fn mp_xtom |
101returns an 102.Vt MINT 103with the value of 104.Fa s , 105which is treated to be in hexadecimal. 106The return values from | 101returns an 102.Vt MINT 103with the value of 104.Fa s , 105which is treated to be in hexadecimal. 106The return values from |
107.Fn itom | 107.Fn mp_itom |
108and | 108and |
109.Fn xtom | 109.Fn mp_xtom |
110must be released with | 110must be released with |
111.Fn mfree | 111.Fn mp_mfree |
112when they are no longer needed. | 112when they are no longer needed. |
113.Fn mtox | 113.Fn mp_mtox |
114returns a null-terminated hexadecimal string having the value of 115.Fa mp ; 116its return value must be released with 117.Fn free 118.Pq Xr free 3 119when it is no longer needed. 120.Ed 121.Pp 122.Ft void | 114returns a null-terminated hexadecimal string having the value of 115.Fa mp ; 116its return value must be released with 117.Fn free 118.Pq Xr free 3 119when it is no longer needed. 120.Ed 121.Pp 122.Ft void |
123.Fn madd "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ; | 123.Fn mp_madd "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ; |
124.Pp 125.Ft void | 124.Pp 125.Ft void |
126.Fn msub "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ; | 126.Fn mp_msub "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ; |
127.Pp 128.Ft void | 127.Pp 128.Ft void |
129.Fn mult "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ; | 129.Fn mp_mult "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ; |
130.Bd -ragged -offset indent | 130.Bd -ragged -offset indent |
131.Fn madd , 132.Fn msub , | 131.Fn mp_madd , 132.Fn mp_msub , |
133and | 133and |
134.Fn mult | 134.Fn mp_mult |
135store the sum, difference, or product, respectively, of 136.Fa mp1 137and 138.Fa mp2 139in 140.Fa rmp . 141.Ed 142.Pp 143.Ft void | 135store the sum, difference, or product, respectively, of 136.Fa mp1 137and 138.Fa mp2 139in 140.Fa rmp . 141.Ed 142.Pp 143.Ft void |
144.Fn mdiv "const MINT *nmp" "const MINT *dmp" "MINT *qmp" "MINT *rmp" ; | 144.Fn mp_mdiv "const MINT *nmp" "const MINT *dmp" "MINT *qmp" "MINT *rmp" ; |
145.Pp 146.Ft void | 145.Pp 146.Ft void |
147.Fn sdiv "const MINT *nmp" "short d" "MINT *qmp" "short *ro" ; | 147.Fn mp_sdiv "const MINT *nmp" "short d" "MINT *qmp" "short *ro" ; |
148.Bd -ragged -offset indent | 148.Bd -ragged -offset indent |
149.Fn mdiv | 149.Fn mp_mdiv |
150computes the quotient and remainder of 151.Fa nmp 152and 153.Fa dmp 154and stores the result in 155.Fa qmp 156and 157.Fa rmp , 158respectively. | 150computes the quotient and remainder of 151.Fa nmp 152and 153.Fa dmp 154and stores the result in 155.Fa qmp 156and 157.Fa rmp , 158respectively. |
159.Fn sdiv | 159.Fn mp_sdiv |
160is similar to | 160is similar to |
161.Fn mdiv | 161.Fn mp_mdiv |
162except the divisor 163.Fa ( dmp 164or 165.Fa d ) 166and remainder 167.Fa ( rmp 168or 169.Fa ro ) 170are ordinary integers. 171.Ed 172.Pp 173.Ft void | 162except the divisor 163.Fa ( dmp 164or 165.Fa d ) 166and remainder 167.Fa ( rmp 168or 169.Fa ro ) 170are ordinary integers. 171.Ed 172.Pp 173.Ft void |
174.Fn pow "const MINT *bmp" "const MINT *emp" "const MINT *mmp" "MINT *rmp" ; | 174.Fn mp_pow "const MINT *bmp" "const MINT *emp" "const MINT *mmp" "MINT *rmp" ; |
175.Pp 176.Ft void | 175.Pp 176.Ft void |
177.Fn rpow "const MINT *bmp" "short e" "MINT *rmp" ; | 177.Fn mp_rpow "const MINT *bmp" "short e" "MINT *rmp" ; |
178.Bd -ragged -offset indent | 178.Bd -ragged -offset indent |
179.Fn rpow | 179.Fn mp_rpow |
180computes the result of 181.Fa bmp 182raised to the 183.Fa emp Ns th 184power and reduced modulo 185.Fa mmp ; 186the result is stored in 187.Fa rmp . | 180computes the result of 181.Fa bmp 182raised to the 183.Fa emp Ns th 184power and reduced modulo 185.Fa mmp ; 186the result is stored in 187.Fa rmp . |
188.Fn pow | 188.Fn mp_pow |
189computes the result of 190.Fa bmp 191raised to the 192.Fa e Ns th 193power and stores the result in 194.Fa rmp . 195.Ed 196.Pp 197.Ft void | 189computes the result of 190.Fa bmp 191raised to the 192.Fa e Ns th 193power and stores the result in 194.Fa rmp . 195.Ed 196.Pp 197.Ft void |
198.Fn min "MINT *mp" ; | 198.Fn mp_min "MINT *mp" ; |
199.Pp 200.Ft void | 199.Pp 200.Ft void |
201.Fn mout "const MINT *mp" ; | 201.Fn mp_mout "const MINT *mp" ; |
202.Bd -ragged -offset indent | 202.Bd -ragged -offset indent |
203.Fn min | 203.Fn mp_min |
204reads a line from standard input, tries to interpret it as a decimal 205number, and if successful, stores the result in 206.Fa mp . | 204reads a line from standard input, tries to interpret it as a decimal 205number, and if successful, stores the result in 206.Fa mp . |
207.Fn mout | 207.Fn mp_mout |
208prints the value, in decimal, of 209.Fa mp 210to standard output (without a trailing newline). 211.Ed 212.Pp 213.Ft void | 208prints the value, in decimal, of 209.Fa mp 210to standard output (without a trailing newline). 211.Ed 212.Pp 213.Ft void |
214.Fn gcd "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ; | 214.Fn mp_gcd "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ; |
215.Bd -ragged -offset indent | 215.Bd -ragged -offset indent |
216.Fn gcd | 216.Fn mp_gcd |
217computes the greatest common divisor of 218.Fa mp1 219and 220.Fa mp2 221and stores the result in 222.Fa rmp . 223.Ed 224.Pp 225.Ft int | 217computes the greatest common divisor of 218.Fa mp1 219and 220.Fa mp2 221and stores the result in 222.Fa rmp . 223.Ed 224.Pp 225.Ft int |
226.Fn mcmp "const MINT *mp1" "const MINT *mp2" ; | 226.Fn mp_mcmp "const MINT *mp1" "const MINT *mp2" ; |
227.Bd -ragged -offset indent 228.Fa mcmp 229compares the values of 230.Fa mp1 231and 232.Fa mp2 233and returns 2340 if the two values are equal, 235a value greater than 0 if 236.Fa mp1 237is greater than 238.Fa mp2 , 239and a value less than 0 if 240.Fa mp2 241is greater than 242.Fa mp1 . 243.Ed 244.Pp 245.Ft void | 227.Bd -ragged -offset indent 228.Fa mcmp 229compares the values of 230.Fa mp1 231and 232.Fa mp2 233and returns 2340 if the two values are equal, 235a value greater than 0 if 236.Fa mp1 237is greater than 238.Fa mp2 , 239and a value less than 0 if 240.Fa mp2 241is greater than 242.Fa mp1 . 243.Ed 244.Pp 245.Ft void |
246.Fn move "const MINT *smp" "MINT *tmp" ; | 246.Fn mp_move "const MINT *smp" "MINT *tmp" ; |
247.Bd -ragged -offset indent | 247.Bd -ragged -offset indent |
248.Fn move | 248.Fn mp_move |
249copies the value of 250.Fa smp 251to 252.Fa tmp 253(both values must be initialized). 254.Ed 255.Pp 256.Ft void | 249copies the value of 250.Fa smp 251to 252.Fa tmp 253(both values must be initialized). 254.Ed 255.Pp 256.Ft void |
257.Fn msqrt "const MINT *nmp" "MINT *xmp" "MINT *rmp" ; | 257.Fn mp_msqrt "const MINT *nmp" "MINT *xmp" "MINT *rmp" ; |
258.Bd -ragged -offset indent | 258.Bd -ragged -offset indent |
259.Fn msqrt | 259.Fn mp_msqrt |
260computes the square root and remainder of 261.Fa nmp 262and stores them in 263.Fa xmp 264and 265.Fa rmp , 266respectively. 267.Ed --- 23 unchanged lines hidden (view full) --- 291.Fx 2.2 292shipped with a 293.Nm 294implemented in terms of 295.Nm libgmp . 296This implementation appeared in 297.Fx 5.0 . 298.Sh BUGS | 260computes the square root and remainder of 261.Fa nmp 262and stores them in 263.Fa xmp 264and 265.Fa rmp , 266respectively. 267.Ed --- 23 unchanged lines hidden (view full) --- 291.Fx 2.2 292shipped with a 293.Nm 294implemented in terms of 295.Nm libgmp . 296This implementation appeared in 297.Fx 5.0 . 298.Sh BUGS |
299The 300.Fn pow 301routine exists in both 302.Nm libmp 303and 304.Nm libm 305with incompatible semantics. 306.Pp | |
307Errors are reported via output to standard error and abnormal 308program termination instead of via return values. 309The application cannot control this behavior. 310.Pp 311It is not clear whether the string returned by | 299Errors are reported via output to standard error and abnormal 300program termination instead of via return values. 301The application cannot control this behavior. 302.Pp 303It is not clear whether the string returned by |
312.Fn mtox | 304.Fn mp_mtox |
313may be written to by the caller. 314This implementation allows it, but others may not. 315Ideally, | 305may be written to by the caller. 306This implementation allows it, but others may not. 307Ideally, |
316.Fn mtox | 308.Fn mp_mtox |
317would take a pointer to a buffer to fill in. 318.Pp 319It is not clear whether using the same variable as both source and 320destination in a single invocation is permitted. 321Some of the calls in this implementation allow this, while others 322do not. | 309would take a pointer to a buffer to fill in. 310.Pp 311It is not clear whether using the same variable as both source and 312destination in a single invocation is permitted. 313Some of the calls in this implementation allow this, while others 314do not. |