| 1 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 |
| 2 | .\" |
| 3 | .\" Standard preamble: |
| 4 | .\" ======================================================================== |
| 5 | .de Sh \" Subsection heading |
| 6 | .br |
| 7 | .if t .Sp |
| 8 | .ne 5 |
| 9 | .PP |
| 10 | \fB\\$1\fR |
| 11 | .PP |
| 12 | .. |
| 13 | .de Sp \" Vertical space (when we can't use .PP) |
| 14 | .if t .sp .5v |
| 15 | .if n .sp |
| 16 | .. |
| 17 | .de Vb \" Begin verbatim text |
| 18 | .ft CW |
| 19 | .nf |
| 20 | .ne \\$1 |
| 21 | .. |
| 22 | .de Ve \" End verbatim text |
| 23 | .ft R |
| 24 | .fi |
| 25 | .. |
| 26 | .\" Set up some character translations and predefined strings. \*(-- will |
| 27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left |
| 28 | .\" double quote, and \*(R" will give a right double quote. | will give a |
| 29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to |
| 30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' |
| 31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. |
| 32 | .tr \(*W-|\(bv\*(Tr |
| 33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' |
| 34 | .ie n \{\ |
| 35 | . ds -- \(*W- |
| 36 | . ds PI pi |
| 37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch |
| 38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch |
| 39 | . ds L" "" |
| 40 | . ds R" "" |
| 41 | . ds C` "" |
| 42 | . ds C' "" |
| 43 | 'br\} |
| 44 | .el\{\ |
| 45 | . ds -- \|\(em\| |
| 46 | . ds PI \(*p |
| 47 | . ds L" `` |
| 48 | . ds R" '' |
| 49 | 'br\} |
| 50 | .\" |
| 51 | .\" If the F register is turned on, we'll generate index entries on stderr for |
| 52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index |
| 53 | .\" entries marked with X<> in POD. Of course, you'll have to process the |
| 54 | .\" output yourself in some meaningful fashion. |
| 55 | .if \nF \{\ |
| 56 | . de IX |
| 57 | . tm Index:\\$1\t\\n%\t"\\$2" |
| 58 | .. |
| 59 | . nr % 0 |
| 60 | . rr F |
| 61 | .\} |
| 62 | .\" |
| 63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 64 | .\" way too many mistakes in technical documents. |
| 65 | .hy 0 |
| 66 | .if n .na |
| 67 | .\" |
| 68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). |
| 69 | .\" Fear. Run. Save yourself. No user-serviceable parts. |
| 70 | . \" fudge factors for nroff and troff |
| 71 | .if n \{\ |
| 72 | . ds #H 0 |
| 73 | . ds #V .8m |
| 74 | . ds #F .3m |
| 75 | . ds #[ \f1 |
| 76 | . ds #] \fP |
| 77 | .\} |
| 78 | .if t \{\ |
| 79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) |
| 80 | . ds #V .6m |
| 81 | . ds #F 0 |
| 82 | . ds #[ \& |
| 83 | . ds #] \& |
| 84 | .\} |
| 85 | . \" simple accents for nroff and troff |
| 86 | .if n \{\ |
| 87 | . ds ' \& |
| 88 | . ds ` \& |
| 89 | . ds ^ \& |
| 90 | . ds , \& |
| 91 | . ds ~ ~ |
| 92 | . ds / |
| 93 | .\} |
| 94 | .if t \{\ |
| 95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" |
| 96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' |
| 97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' |
| 98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' |
| 99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' |
| 100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' |
| 101 | .\} |
| 102 | . \" troff and (daisy-wheel) nroff accents |
| 103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' |
| 104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' |
| 105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] |
| 106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' |
| 107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' |
| 108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] |
| 109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] |
| 110 | .ds ae a\h'-(\w'a'u*4/10)'e |
| 111 | .ds Ae A\h'-(\w'A'u*4/10)'E |
| 112 | . \" corrections for vroff |
| 113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' |
| 114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' |
| 115 | . \" for low resolution devices (crt and lpr) |
| 116 | .if \n(.H>23 .if \n(.V>19 \ |
| 117 | \{\ |
| 118 | . ds : e |
| 119 | . ds 8 ss |
| 120 | . ds o a |
| 121 | . ds d- d\h'-1'\(ga |
| 122 | . ds D- D\h'-1'\(hy |
| 123 | . ds th \o'bp' |
| 124 | . ds Th \o'LP' |
| 125 | . ds ae ae |
| 126 | . ds Ae AE |
| 127 | .\} |
| 128 | .rm #[ #] #H #V #F C |
| 129 | .\" ======================================================================== |
| 130 | .\" |
| 131 | .IX Title "Math::BigInt::Calc 3" |
| 132 | .TH Math::BigInt::Calc 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide" |
| 133 | .SH "NAME" |
| 134 | Math::BigInt::Calc \- Pure Perl module to support Math::BigInt |
| 135 | .SH "SYNOPSIS" |
| 136 | .IX Header "SYNOPSIS" |
| 137 | Provides support for big integer calculations. Not intended to be used by other |
| 138 | modules. Other modules which sport the same functions can also be used to support |
| 139 | Math::BigInt, like Math::BigInt::GMP or Math::BigInt::Pari. |
| 140 | .SH "DESCRIPTION" |
| 141 | .IX Header "DESCRIPTION" |
| 142 | In order to allow for multiple big integer libraries, Math::BigInt was |
| 143 | rewritten to use library modules for core math routines. Any module which |
| 144 | follows the same \s-1API\s0 as this can be used instead by using the following: |
| 145 | .PP |
| 146 | .Vb 1 |
| 147 | \& use Math::BigInt lib => 'libname'; |
| 148 | .Ve |
| 149 | .PP |
| 150 | \&'libname' is either the long name ('Math::BigInt::Pari'), or only the short |
| 151 | version like 'Pari'. |
| 152 | .SH "STORAGE" |
| 153 | .IX Header "STORAGE" |
| 154 | .SH "METHODS" |
| 155 | .IX Header "METHODS" |
| 156 | The following functions \s-1MUST\s0 be defined in order to support the use by |
| 157 | Math::BigInt v1.70 or later: |
| 158 | .PP |
| 159 | .Vb 6 |
| 160 | \& api_version() return API version, minimum 1 for v1.70 |
| 161 | \& _new(string) return ref to new object from ref to decimal string |
| 162 | \& _zero() return a new object with value 0 |
| 163 | \& _one() return a new object with value 1 |
| 164 | \& _two() return a new object with value 2 |
| 165 | \& _ten() return a new object with value 10 |
| 166 | .Ve |
| 167 | .PP |
| 168 | .Vb 5 |
| 169 | \& _str(obj) return ref to a string representing the object |
| 170 | \& _num(obj) returns a Perl integer/floating point number |
| 171 | \& NOTE: because of Perl numeric notation defaults, |
| 172 | \& the _num'ified obj may lose accuracy due to |
| 173 | \& machine-dependend floating point size limitations |
| 174 | .Ve |
| 175 | .PP |
| 176 | .Vb 15 |
| 177 | \& _add(obj,obj) Simple addition of two objects |
| 178 | \& _mul(obj,obj) Multiplication of two objects |
| 179 | \& _div(obj,obj) Division of the 1st object by the 2nd |
| 180 | \& In list context, returns (result,remainder). |
| 181 | \& NOTE: this is integer math, so no |
| 182 | \& fractional part will be returned. |
| 183 | \& The second operand will be not be 0, so no need to |
| 184 | \& check for that. |
| 185 | \& _sub(obj,obj) Simple subtraction of 1 object from another |
| 186 | \& a third, optional parameter indicates that the params |
| 187 | \& are swapped. In this case, the first param needs to |
| 188 | \& be preserved, while you can destroy the second. |
| 189 | \& sub (x,y,1) => return x - y and keep x intact! |
| 190 | \& _dec(obj) decrement object by one (input is garant. to be > 0) |
| 191 | \& _inc(obj) increment object by one |
| 192 | .Ve |
| 193 | .PP |
| 194 | .Vb 1 |
| 195 | \& _acmp(obj,obj) <=> operator for objects (return -1, 0 or 1) |
| 196 | .Ve |
| 197 | .PP |
| 198 | .Vb 2 |
| 199 | \& _len(obj) returns count of the decimal digits of the object |
| 200 | \& _digit(obj,n) returns the n'th decimal digit of object |
| 201 | .Ve |
| 202 | .PP |
| 203 | .Vb 6 |
| 204 | \& _is_one(obj) return true if argument is 1 |
| 205 | \& _is_two(obj) return true if argument is 2 |
| 206 | \& _is_ten(obj) return true if argument is 10 |
| 207 | \& _is_zero(obj) return true if argument is 0 |
| 208 | \& _is_even(obj) return true if argument is even (0,2,4,6..) |
| 209 | \& _is_odd(obj) return true if argument is odd (1,3,5,7..) |
| 210 | .Ve |
| 211 | .PP |
| 212 | .Vb 1 |
| 213 | \& _copy return a ref to a true copy of the object |
| 214 | .Ve |
| 215 | .PP |
| 216 | .Vb 2 |
| 217 | \& _check(obj) check whether internal representation is still intact |
| 218 | \& return 0 for ok, otherwise error message as string |
| 219 | .Ve |
| 220 | .PP |
| 221 | .Vb 2 |
| 222 | \& _from_hex(str) return ref to new object from ref to hexadecimal string |
| 223 | \& _from_bin(str) return ref to new object from ref to binary string |
| 224 | .Ve |
| 225 | .PP |
| 226 | .Vb 6 |
| 227 | \& _as_hex(str) return string containing the value as |
| 228 | \& unsigned hex string, with the '0x' prepended. |
| 229 | \& Leading zeros must be stripped. |
| 230 | \& _as_bin(str) Like as_hex, only as binary string containing only |
| 231 | \& zeros and ones. Leading zeros must be stripped and a |
| 232 | \& '0b' must be prepended. |
| 233 | .Ve |
| 234 | .PP |
| 235 | .Vb 2 |
| 236 | \& _rsft(obj,N,B) shift object in base B by N 'digits' right |
| 237 | \& _lsft(obj,N,B) shift object in base B by N 'digits' left |
| 238 | .Ve |
| 239 | .PP |
| 240 | .Vb 4 |
| 241 | \& _xor(obj1,obj2) XOR (bit-wise) object 1 with object 2 |
| 242 | \& Note: XOR, AND and OR pad with zeros if size mismatches |
| 243 | \& _and(obj1,obj2) AND (bit-wise) object 1 with object 2 |
| 244 | \& _or(obj1,obj2) OR (bit-wise) object 1 with object 2 |
| 245 | .Ve |
| 246 | .PP |
| 247 | .Vb 16 |
| 248 | \& _mod(obj,obj) Return remainder of div of the 1st by the 2nd object |
| 249 | \& _sqrt(obj) return the square root of object (truncated to int) |
| 250 | \& _root(obj) return the n'th (n >= 3) root of obj (truncated to int) |
| 251 | \& _fac(obj) return factorial of object 1 (1*2*3*4..) |
| 252 | \& _pow(obj,obj) return object 1 to the power of object 2 |
| 253 | \& return undef for NaN |
| 254 | \& _zeros(obj) return number of trailing decimal zeros |
| 255 | \& _modinv return inverse modulus |
| 256 | \& _modpow return modulus of power ($x ** $y) % $z |
| 257 | \& _log_int(X,N) calculate integer log() of X in base N |
| 258 | \& X >= 0, N >= 0 (return undef for NaN) |
| 259 | \& returns (RESULT, EXACT) where EXACT is: |
| 260 | \& 1 : result is exactly RESULT |
| 261 | \& 0 : result was truncated to RESULT |
| 262 | \& undef : unknown whether result is exactly RESULT |
| 263 | \& _gcd(obj,obj) return Greatest Common Divisor of two objects |
| 264 | .Ve |
| 265 | .PP |
| 266 | The following functions are optional, and can be defined if the underlying lib |
| 267 | has a fast way to do them. If undefined, Math::BigInt will use pure Perl (hence |
| 268 | slow) fallback routines to emulate these: |
| 269 | .PP |
| 270 | .Vb 3 |
| 271 | \& _signed_or |
| 272 | \& _signed_and |
| 273 | \& _signed_xor |
| 274 | .Ve |
| 275 | .PP |
| 276 | Input strings come in as unsigned but with prefix (i.e. as '123', '0xabc' |
| 277 | or '0b1101'). |
| 278 | .PP |
| 279 | So the library needs only to deal with unsigned big integers. Testing of input |
| 280 | parameter validity is done by the caller, so you need not worry about |
| 281 | underflow (f.i. in \f(CW\*(C`_sub()\*(C'\fR, \f(CW\*(C`_dec()\*(C'\fR) nor about division by zero or similar |
| 282 | cases. |
| 283 | .PP |
| 284 | The first parameter can be modified, that includes the possibility that you |
| 285 | return a reference to a completely different object instead. Although keeping |
| 286 | the reference and just changing it's contents is prefered over creating and |
| 287 | returning a different reference. |
| 288 | .PP |
| 289 | Return values are always references to objects, strings, or true/false for |
| 290 | comparisation routines. |
| 291 | .SH "WRAP YOUR OWN" |
| 292 | .IX Header "WRAP YOUR OWN" |
| 293 | If you want to port your own favourite c\-lib for big numbers to the |
| 294 | Math::BigInt interface, you can take any of the already existing modules as |
| 295 | a rough guideline. You should really wrap up the latest BigInt and BigFloat |
| 296 | testsuites with your module, and replace in them any of the following: |
| 297 | .PP |
| 298 | .Vb 1 |
| 299 | \& use Math::BigInt; |
| 300 | .Ve |
| 301 | .PP |
| 302 | by this: |
| 303 | .PP |
| 304 | .Vb 1 |
| 305 | \& use Math::BigInt lib => 'yourlib'; |
| 306 | .Ve |
| 307 | .PP |
| 308 | This way you ensure that your library really works 100% within Math::BigInt. |
| 309 | .SH "LICENSE" |
| 310 | .IX Header "LICENSE" |
| 311 | This program is free software; you may redistribute it and/or modify it under |
| 312 | the same terms as Perl itself. |
| 313 | .SH "AUTHORS" |
| 314 | .IX Header "AUTHORS" |
| 315 | Original math code by Mark Biggar, rewritten by Tels <http://bloodgate.com/> |
| 316 | in late 2000. |
| 317 | Seperated from BigInt and shaped \s-1API\s0 with the help of John Peacock. |
| 318 | .PP |
| 319 | Fixed, speed\-up, streamlined and enhanced by Tels 2001 \- 2005. |
| 320 | .SH "SEE ALSO" |
| 321 | .IX Header "SEE ALSO" |
| 322 | Math::BigInt, Math::BigFloat, Math::BigInt::BitVect, |
| 323 | Math::BigInt::GMP, Math::BigInt::FastCalc and Math::BigInt::Pari. |