Debian Codegraph @

upstream/mageia-cauldron/man3pm/Math::BigInt::Lib.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Math::BigInt::Lib 3pm"
61 .TH Math::BigInt::Lib 3pm 2025-06-24 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Math::BigInt::Lib \- virtual parent class for Math::BigInt libraries
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& # In the backend library for Math::BigInt et al.
72 \&
73 \& package Math::BigInt::MyBackend;
74 \&
75 \& use Math::BigInt::Lib;
76 \& our @ISA = qw< Math::BigInt::Lib >;
77 \&
78 \& sub _new { ... }
79 \& sub _str { ... }
80 \& sub _add { ... }
81 \& str _sub { ... }
82 \& ...
83 \&
84 \& # In your main program.
85 \&
86 \& use Math::BigInt lib => \*(AqMyBackend\*(Aq;
87 .Ve
88 .SH DESCRIPTION
89 .IX Header "DESCRIPTION"
90 This module provides support for big integer calculations. It is not intended
91 to be used directly, but rather as a parent class for backend libraries used by
92 Math::BigInt, Math::BigFloat, Math::BigRat, and related modules.
93 .PP
94 Other backend libraries include Math::BigInt::Calc, Math::BigInt::FastCalc,
95 Math::BigInt::GMP, and Math::BigInt::Pari.
96 .PP
97 In order to allow for multiple big integer libraries, Math::BigInt was
98 rewritten to use a plug\-in library for core math routines. Any module which
99 conforms to the API can be used by Math::BigInt by using this in your program:
100 .PP
101 .Vb 1
102 \& use Math::BigInt lib => \*(Aqlibname\*(Aq;
103 .Ve
104 .PP
105 \&\*(Aqlibname\*(Aq is either the long name, like \*(AqMath::BigInt::Pari\*(Aq, or only the short
106 version, like \*(AqPari\*(Aq.
107 .SS "General Notes"
108 .IX Subsection "General Notes"
109 A library only needs to deal with unsigned big integers. Testing of input
110 parameter validity is done by the caller, so there is no need to worry about
111 underflow (e.g., in \f(CW_sub()\fR and \f(CW_dec()\fR) or about division by zero (e.g.,
112 in \f(CW_div()\fR and \f(CW_mod()\fR)) or similar cases.
113 .PP
114 Some libraries use methods that don\*(Aqt modify their argument, and some libraries
115 don\*(Aqt even use objects, but rather unblessed references. Because of this,
116 liberary methods are always called as class methods, not instance methods:
117 .PP
118 .Vb 3
119 \& $x = Class \-> method($x, $y); # like this
120 \& $x = $x \-> method($y); # not like this ...
121 \& $x \-> method($y); # ... or like this
122 .Ve
123 .PP
124 And with boolean methods
125 .PP
126 .Vb 2
127 \& $bool = Class \-> method($x, $y); # like this
128 \& $bool = $x \-> method($y); # not like this
129 .Ve
130 .PP
131 Return values are always objects, strings, Perl scalars, or true/false for
132 comparison routines.
133 .PP
134 \fIAPI version\fR
135 .IX Subsection "API version"
136 .IP CLASS\->\fBapi_version()\fR 4
137 .IX Item "CLASS->api_version()"
138 This method is no longer used and can be omitted. Methods that are not
139 implemented by a subclass will be inherited from this class.
140 .PP
141 \fIConstructors\fR
142 .IX Subsection "Constructors"
143 .PP
144 The following methods are mandatory: \fB_new()\fR, \fB_str()\fR, \fB_add()\fR, and \fB_sub()\fR.
145 However, computations will be very slow without \fB_mul()\fR and \fB_div()\fR.
146 .IP CLASS\->_new(STR) 4
147 .IX Item "CLASS->_new(STR)"
148 Convert a string representing an unsigned decimal number to an object
149 representing the same number. The input is normalized, i.e., it matches
150 \&\f(CW\*(C`^(0|[1\-9]\ed*)$\*(C'\fR.
151 .IP CLASS\->\fB_zero()\fR 4
152 .IX Item "CLASS->_zero()"
153 Return an object representing the number zero.
154 .IP CLASS\->\fB_one()\fR 4
155 .IX Item "CLASS->_one()"
156 Return an object representing the number one.
157 .IP CLASS\->\fB_two()\fR 4
158 .IX Item "CLASS->_two()"
159 Return an object representing the number two.
160 .IP CLASS\->\fB_ten()\fR 4
161 .IX Item "CLASS->_ten()"
162 Return an object representing the number ten.
163 .IP CLASS\->_from_bin(STR) 4
164 .IX Item "CLASS->_from_bin(STR)"
165 Return an object given a string representing a binary number. The input has a
166 \&\*(Aq0b\*(Aq prefix and matches the regular expression \f(CW\*(C`^0[bB](0|1[01]*)$\*(C'\fR.
167 .IP CLASS\->_from_oct(STR) 4
168 .IX Item "CLASS->_from_oct(STR)"
169 Return an object given a string representing an octal number. The input has a
170 \&\*(Aq0\*(Aq prefix and matches the regular expression \f(CW\*(C`^0[1\-7]*$\*(C'\fR.
171 .IP CLASS\->_from_hex(STR) 4
172 .IX Item "CLASS->_from_hex(STR)"
173 Return an object given a string representing a hexadecimal number. The input
174 has a \*(Aq0x\*(Aq prefix and matches the regular expression
175 \&\f(CW\*(C`^0x(0|[1\-9a\-fA\-F][\eda\-fA\-F]*)$\*(C'\fR.
176 .IP CLASS\->_from_bytes(STR) 4
177 .IX Item "CLASS->_from_bytes(STR)"
178 Returns an object given a byte string representing the number. The byte string
179 is in big endian byte order, so the two\-byte input string "\ex01\ex00" should
180 give an output value representing the number 256.
181 .IP "CLASS\->_from_base(STR, BASE, COLLSEQ)" 4
182 .IX Item "CLASS->_from_base(STR, BASE, COLLSEQ)"
183 Returns an object given a string STR, a base BASE, and a collation sequence
184 COLLSEQ. Each character in STR represents a numerical value identical to the
185 character\*(Aqs position in COLLSEQ. All characters in STR must be present in
186 COLLSEQ.
187 .Sp
188 If BASE is less than or equal to 94, and a collation sequence is not specified,
189 the following default collation sequence is used. It contains of all the 94
190 printable ASCII characters except space/blank:
191 .Sp
192 .Vb 7
193 \& 0123456789 # ASCII 48 to 57
194 \& ABCDEFGHIJKLMNOPQRSTUVWXYZ # ASCII 65 to 90
195 \& abcdefghijklmnopqrstuvwxyz # ASCII 97 to 122
196 \& !"#$%&\*(Aq()*+,\-./ # ASCII 33 to 47
197 \& :;<=>?@ # ASCII 58 to 64
198 \& [\e]^_\` # ASCII 91 to 96
199 \& {|}~ # ASCII 123 to 126
200 .Ve
201 .Sp
202 If the default collation sequence is used, and the BASE is less than or equal
203 to 36, the letter case in STR is ignored.
204 .Sp
205 For instance, with base 3 and collation sequence "\-/|", the character "\-"
206 represents 0, "/" represents 1, and "|" represents 2. So if STR is "/|\-", the
207 output is 1 * 3**2 + 2 * 3**1 + 0 * 3**0 = 15.
208 .Sp
209 The following examples show standard binary, octal, decimal, and hexadecimal
210 conversion. All examples return 250.
211 .Sp
212 .Vb 4
213 \& $x = $class \-> _from_base("11111010", 2)
214 \& $x = $class \-> _from_base("372", 8)
215 \& $x = $class \-> _from_base("250", 10)
216 \& $x = $class \-> _from_base("FA", 16)
217 .Ve
218 .Sp
219 Some more examples, all returning 250:
220 .Sp
221 .Vb 6
222 \& $x = $class \-> _from_base("100021", 3)
223 \& $x = $class \-> _from_base("3322", 4)
224 \& $x = $class \-> _from_base("2000", 5)
225 \& $x = $class \-> _from_base("caaa", 5, "abcde")
226 \& $x = $class \-> _from_base("42", 62)
227 \& $x = $class \-> _from_base("2!", 94)
228 .Ve
229 .IP "CLASS\->_from_base_num(ARRAY, BASE)" 4
230 .IX Item "CLASS->_from_base_num(ARRAY, BASE)"
231 Returns an object given an array of values and a base. This method is
232 equivalent to \f(CW_from_base()\fR, but works on numbers in an array rather than
233 characters in a string. Unlike \f(CW_from_base()\fR, all input values may be
234 arbitrarily large.
235 .Sp
236 .Vb 2
237 \& $x = $class \-> _from_base_num([1, 1, 0, 1], 2) # $x is 13
238 \& $x = $class \-> _from_base_num([3, 125, 39], 128) # $x is 65191
239 .Ve
240 .PP
241 \fIMathematical functions\fR
242 .IX Subsection "Mathematical functions"
243 .IP "CLASS\->_add(OBJ1, OBJ2)" 4
244 .IX Item "CLASS->_add(OBJ1, OBJ2)"
245 Addition. Returns the result of adding OBJ2 to OBJ1.
246 .IP "CLASS\->_mul(OBJ1, OBJ2)" 4
247 .IX Item "CLASS->_mul(OBJ1, OBJ2)"
248 Multiplication. Returns the result of multiplying OBJ2 and OBJ1.
249 .IP "CLASS\->_div(OBJ1, OBJ2)" 4
250 .IX Item "CLASS->_div(OBJ1, OBJ2)"
251 Division. In scalar context, returns the quotient after dividing OBJ1 by OBJ2
252 and truncating the result to an integer. In list context, return the quotient
253 and the remainder.
254 .IP "CLASS\->_sub(OBJ1, OBJ2, FLAG)" 4
255 .IX Item "CLASS->_sub(OBJ1, OBJ2, FLAG)"
256 .PD 0
257 .IP "CLASS\->_sub(OBJ1, OBJ2)" 4
258 .IX Item "CLASS->_sub(OBJ1, OBJ2)"
259 .PD
260 Subtraction. Returns the result of subtracting OBJ2 by OBJ1. If \f(CW\*(C`flag\*(C'\fR is false
261 or omitted, OBJ1 might be modified. If \f(CW\*(C`flag\*(C'\fR is true, OBJ2 might be modified.
262 .IP "CLASS\->_sadd(OBJ1, SIGN1, OBJ2, SIGN2)" 4
263 .IX Item "CLASS->_sadd(OBJ1, SIGN1, OBJ2, SIGN2)"
264 Signed addition. Returns the result of adding OBJ2 with sign SIGN2 to OBJ1 with
265 sign SIGN1.
266 .Sp
267 .Vb 1
268 \& ($obj3, $sign3) = $class \-> _sadd($obj1, $sign1, $obj2, $sign2);
269 .Ve
270 .IP "CLASS\->_ssub(OBJ1, SIGN1, OBJ2, SIGN2)" 4
271 .IX Item "CLASS->_ssub(OBJ1, SIGN1, OBJ2, SIGN2)"
272 Signed subtraction. Returns the result of subtracting OBJ2 with sign SIGN2 to
273 OBJ1 with sign SIGN1.
274 .Sp
275 .Vb 1
276 \& ($obj3, $sign3) = $class \-> _sadd($obj1, $sign1, $obj2, $sign2);
277 .Ve
278 .IP CLASS\->_dec(OBJ) 4
279 .IX Item "CLASS->_dec(OBJ)"
280 Returns the result after decrementing OBJ by one.
281 .IP CLASS\->_inc(OBJ) 4
282 .IX Item "CLASS->_inc(OBJ)"
283 Returns the result after incrementing OBJ by one.
284 .IP "CLASS\->_mod(OBJ1, OBJ2)" 4
285 .IX Item "CLASS->_mod(OBJ1, OBJ2)"
286 Returns OBJ1 modulo OBJ2, i.e., the remainder after dividing OBJ1 by OBJ2.
287 .IP CLASS\->_sqrt(OBJ) 4
288 .IX Item "CLASS->_sqrt(OBJ)"
289 Returns the square root of OBJ, truncated to an integer.
290 .IP "CLASS\->_root(OBJ, N)" 4
291 .IX Item "CLASS->_root(OBJ, N)"
292 Returns the Nth root of OBJ, truncated to an integer.
293 .IP CLASS\->_fac(OBJ) 4
294 .IX Item "CLASS->_fac(OBJ)"
295 Returns the factorial of OBJ, i.e., the product of all positive integers up to
296 and including OBJ.
297 .IP CLASS\->_dfac(OBJ) 4
298 .IX Item "CLASS->_dfac(OBJ)"
299 Returns the double factorial of OBJ. If OBJ is an even integer, returns the
300 product of all positive, even integers up to and including OBJ, i.e.,
301 2*4*6*...*OBJ. If OBJ is an odd integer, returns the product of all positive,
302 odd integers, i.e., 1*3*5*...*OBJ.
303 .IP "CLASS\->_pow(OBJ1, OBJ2)" 4
304 .IX Item "CLASS->_pow(OBJ1, OBJ2)"
305 Returns OBJ1 raised to the power of OBJ2. By convention, 0**0 = 1.
306 .IP "CLASS\->_modinv(OBJ1, OBJ2)" 4
307 .IX Item "CLASS->_modinv(OBJ1, OBJ2)"
308 Returns the modular multiplicative inverse, i.e., return OBJ3 so that
309 .Sp
310 .Vb 1
311 \& (OBJ3 * OBJ1) % OBJ2 = 1 % OBJ2
312 .Ve
313 .Sp
314 The result is returned as two arguments. If the modular multiplicative inverse
315 does not exist, both arguments are undefined. Otherwise, the arguments are a
316 number (object) and its sign ("+" or "\-").
317 .Sp
318 The output value, with its sign, must either be a positive value in the range
319 1,2,...,OBJ2\-1 or the same value subtracted OBJ2. For instance, if the input
320 arguments are objects representing the numbers 7 and 5, the method must either
321 return an object representing the number 3 and a "+" sign, since (3*7) % 5 = 1
322 % 5, or an object representing the number 2 and a "\-" sign, since (\-2*7) % 5 = 1
323 % 5.
324 .IP "CLASS\->_modpow(OBJ1, OBJ2, OBJ3)" 4
325 .IX Item "CLASS->_modpow(OBJ1, OBJ2, OBJ3)"
326 Returns the modular exponentiation, i.e., (OBJ1 ** OBJ2) % OBJ3.
327 .IP "CLASS\->_rsft(OBJ, N, B)" 4
328 .IX Item "CLASS->_rsft(OBJ, N, B)"
329 Returns the result after shifting OBJ N digits to thee right in base B. This is
330 equivalent to performing integer division by B**N and discarding the remainder,
331 except that it might be much faster.
332 .Sp
333 For instance, if the object \f(CW$obj\fR represents the hexadecimal number 0xabcde,
334 then \f(CW\*(C`_rsft($obj, 2, 16)\*(C'\fR returns an object representing the number 0xabc. The
335 "remainer", 0xde, is discarded and not returned.
336 .IP "CLASS\->_lsft(OBJ, N, B)" 4
337 .IX Item "CLASS->_lsft(OBJ, N, B)"
338 Returns the result after shifting OBJ N digits to the left in base B. This is
339 equivalent to multiplying by B**N, except that it might be much faster.
340 .IP "CLASS\->_log_int(OBJ, B)" 4
341 .IX Item "CLASS->_log_int(OBJ, B)"
342 Returns the logarithm of OBJ to base BASE truncted to an integer. This method
343 has two output arguments, the OBJECT and a STATUS. The STATUS is Perl scalar;
344 it is 1 if OBJ is the exact result, 0 if the result was truncted to give OBJ,
345 and undef if it is unknown whether OBJ is the exact result.
346 .IP CLASS\->_ilog2(OBJ) 4
347 .IX Item "CLASS->_ilog2(OBJ)"
348 Returns the base 2 logarithm of OBJ rounded downwards to the nearest integer,
349 i.e., \f(CW\*(C`int(log2(OBJ))\*(C'\fR. In list context, this method returns two output
350 arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ
351 is the exact result, 0 if the result was truncted to give OBJ, and undef if it
352 is unknown whether OBJ is the exact result.
353 .Sp
354 This method is equivalent to the more general method \fB_log_int()\fR when it is used
355 with base 2 argument, but \fB_ilog2()\fR method might be faster.
356 .IP CLASS\->_ilog10(OBJ) 4
357 .IX Item "CLASS->_ilog10(OBJ)"
358 Returns the base 10 logarithm of OBJ rounded downwards to the nearest integer,
359 i.e., \f(CW\*(C`int(log2(OBJ))\*(C'\fR. In list context, this method returns two output
360 arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ
361 is the exact result, 0 if the result was truncted to give OBJ, and undef if it
362 is unknown whether OBJ is the exact result.
363 .Sp
364 This method is equivalent to the more general method \fB_log_int()\fR when it is used
365 with base 10 argument, but \fB_ilog10()\fR method might be faster.
366 .Sp
367 Also, the output from \fB_ilog10()\fR is always 1 smaller than the output from
368 \&\fB_len()\fR.
369 .IP CLASS\->_clog2(OBJ) 4
370 .IX Item "CLASS->_clog2(OBJ)"
371 Returns the base 2 logarithm of OBJ rounded upwards to the nearest integer,
372 i.e., \f(CW\*(C`ceil(log2(OBJ))\*(C'\fR. In list context, this method returns two output
373 arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ
374 is the exact result, 0 if the result was truncted to give OBJ, and undef if it
375 is unknown whether OBJ is the exact result.
376 .IP CLASS\->_clog10(OBJ) 4
377 .IX Item "CLASS->_clog10(OBJ)"
378 Returns the base 10 logarithm of OBJ rounded upnwards to the nearest integer,
379 i.e., \f(CW\*(C`ceil(log2(OBJ))\*(C'\fR. In list context, this method returns two output
380 arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ
381 is the exact result, 0 if the result was truncted to give OBJ, and undef if it
382 is unknown whether OBJ is the exact result.
383 .IP "CLASS\->_gcd(OBJ1, OBJ2)" 4
384 .IX Item "CLASS->_gcd(OBJ1, OBJ2)"
385 Returns the greatest common divisor of OBJ1 and OBJ2.
386 .IP "CLASS\->_lcm(OBJ1, OBJ2)" 4
387 .IX Item "CLASS->_lcm(OBJ1, OBJ2)"
388 Return the least common multiple of OBJ1 and OBJ2.
389 .IP CLASS\->_fib(OBJ) 4
390 .IX Item "CLASS->_fib(OBJ)"
391 In scalar context, returns the nth Fibonacci number: \fB_fib\fR\|(0) returns 0, \fB_fib\fR\|(1)
392 returns 1, \fB_fib\fR\|(2) returns 1, \fB_fib\fR\|(3) returns 2 etc. In list context, returns
393 the Fibonacci numbers from F(0) to F(n): 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
394 .IP CLASS\->_lucas(OBJ) 4
395 .IX Item "CLASS->_lucas(OBJ)"
396 In scalar context, returns the nth Lucas number: \fB_lucas\fR\|(0) returns 2, \fB_lucas\fR\|(1)
397 returns 1, \fB_lucas\fR\|(2) returns 3, etc. In list context, returns the Lucas numbers
398 from L(0) to L(n): 2, 1, 3, 4, 7, 11, 18, 29,47, 76, ...
399 .PP
400 \fIBitwise operators\fR
401 .IX Subsection "Bitwise operators"
402 .IP "CLASS\->_and(OBJ1, OBJ2)" 4
403 .IX Item "CLASS->_and(OBJ1, OBJ2)"
404 Returns bitwise and.
405 .IP "CLASS\->_or(OBJ1, OBJ2)" 4
406 .IX Item "CLASS->_or(OBJ1, OBJ2)"
407 Returns bitwise or.
408 .IP "CLASS\->_xor(OBJ1, OBJ2)" 4
409 .IX Item "CLASS->_xor(OBJ1, OBJ2)"
410 Returns bitwise exclusive or.
411 .IP "CLASS\->_sand(OBJ1, OBJ2, SIGN1, SIGN2)" 4
412 .IX Item "CLASS->_sand(OBJ1, OBJ2, SIGN1, SIGN2)"
413 Returns bitwise signed and.
414 .IP "CLASS\->_sor(OBJ1, OBJ2, SIGN1, SIGN2)" 4
415 .IX Item "CLASS->_sor(OBJ1, OBJ2, SIGN1, SIGN2)"
416 Returns bitwise signed or.
417 .IP "CLASS\->_sxor(OBJ1, OBJ2, SIGN1, SIGN2)" 4
418 .IX Item "CLASS->_sxor(OBJ1, OBJ2, SIGN1, SIGN2)"
419 Returns bitwise signed exclusive or.
420 .PP
421 \fIBoolean operators\fR
422 .IX Subsection "Boolean operators"
423 .IP CLASS\->_is_zero(OBJ) 4
424 .IX Item "CLASS->_is_zero(OBJ)"
425 Returns a true value if OBJ is zero, and false value otherwise.
426 .IP CLASS\->_is_one(OBJ) 4
427 .IX Item "CLASS->_is_one(OBJ)"
428 Returns a true value if OBJ is one, and false value otherwise.
429 .IP CLASS\->_is_two(OBJ) 4
430 .IX Item "CLASS->_is_two(OBJ)"
431 Returns a true value if OBJ is two, and false value otherwise.
432 .IP CLASS\->_is_ten(OBJ) 4
433 .IX Item "CLASS->_is_ten(OBJ)"
434 Returns a true value if OBJ is ten, and false value otherwise.
435 .IP CLASS\->_is_even(OBJ) 4
436 .IX Item "CLASS->_is_even(OBJ)"
437 Return a true value if OBJ is an even integer, and a false value otherwise.
438 .IP CLASS\->_is_odd(OBJ) 4
439 .IX Item "CLASS->_is_odd(OBJ)"
440 Return a true value if OBJ is an even integer, and a false value otherwise.
441 .IP "CLASS\->_acmp(OBJ1, OBJ2)" 4
442 .IX Item "CLASS->_acmp(OBJ1, OBJ2)"
443 Compare OBJ1 and OBJ2 and return \-1, 0, or 1, if OBJ1 is numerically less than,
444 equal to, or larger than OBJ2, respectively.
445 .IP "CLASS\->_scmp(OBJ1, SIGN1, OBJ2, SIGN2)" 4
446 .IX Item "CLASS->_scmp(OBJ1, SIGN1, OBJ2, SIGN2)"
447 Compare OBJ1 and OBJ2 and return \-1, 0, or 1, if OBJ1 is numerically less than,
448 equal to, or larger than OBJ2, respectively.
449 .PP
450 \fIString conversion\fR
451 .IX Subsection "String conversion"
452 .IP CLASS\->_str(OBJ) 4
453 .IX Item "CLASS->_str(OBJ)"
454 Returns a string representing OBJ in decimal notation. The returned string
455 should have no leading zeros, i.e., it should match \f(CW\*(C`^(0|[1\-9]\ed*)$\*(C'\fR.
456 .IP CLASS\->_to_bin(OBJ) 4
457 .IX Item "CLASS->_to_bin(OBJ)"
458 Returns the binary string representation of OBJ.
459 .IP CLASS\->_to_oct(OBJ) 4
460 .IX Item "CLASS->_to_oct(OBJ)"
461 Returns the octal string representation of the number.
462 .IP CLASS\->_to_hex(OBJ) 4
463 .IX Item "CLASS->_to_hex(OBJ)"
464 Returns the hexadecimal string representation of the number.
465 .IP CLASS\->_to_bytes(OBJ) 4
466 .IX Item "CLASS->_to_bytes(OBJ)"
467 Returns a byte string representation of OBJ. The byte string is in big endian
468 byte order, so if OBJ represents the number 256, the output should be the
469 two\-byte string "\ex01\ex00".
470 .IP "CLASS\->_to_base(OBJ, BASE, COLLSEQ)" 4
471 .IX Item "CLASS->_to_base(OBJ, BASE, COLLSEQ)"
472 Returns a string representation of OBJ in base BASE with collation sequence
473 COLLSEQ.
474 .Sp
475 .Vb 2
476 \& $val = $class \-> _new("210");
477 \& $str = $class \-> _to_base($val, 10, "xyz") # $str is "zyx"
478 \&
479 \& $val = $class \-> _new("32");
480 \& $str = $class \-> _to_base($val, 2, "\-|") # $str is "|\-\-\-\-\-"
481 .Ve
482 .Sp
483 See \fB_from_base()\fR for more information.
484 .IP "CLASS\->_to_base_num(OBJ, BASE)" 4
485 .IX Item "CLASS->_to_base_num(OBJ, BASE)"
486 Converts the given number to the given base. This method is equivalent to
487 \&\f(CW_to_base()\fR, but returns numbers in an array rather than characters in a
488 string. In the output, the first element is the most significant. Unlike
489 \&\f(CW_to_base()\fR, all input values may be arbitrarily large.
490 .Sp
491 .Vb 2
492 \& $x = $class \-> _to_base_num(13, 2) # $x is [1, 1, 0, 1]
493 \& $x = $class \-> _to_base_num(65191, 128) # $x is [3, 125, 39]
494 .Ve
495 .IP CLASS\->_as_bin(OBJ) 4
496 .IX Item "CLASS->_as_bin(OBJ)"
497 Like \f(CW_to_bin()\fR but with a \*(Aq0b\*(Aq prefix.
498 .IP CLASS\->_as_oct(OBJ) 4
499 .IX Item "CLASS->_as_oct(OBJ)"
500 Like \f(CW_to_oct()\fR but with a \*(Aq0\*(Aq prefix.
501 .IP CLASS\->_as_hex(OBJ) 4
502 .IX Item "CLASS->_as_hex(OBJ)"
503 Like \f(CW_to_hex()\fR but with a \*(Aq0x\*(Aq prefix.
504 .IP CLASS\->_as_bytes(OBJ) 4
505 .IX Item "CLASS->_as_bytes(OBJ)"
506 This is an alias to \f(CW_to_bytes()\fR.
507 .PP
508 \fINumeric conversion\fR
509 .IX Subsection "Numeric conversion"
510 .IP CLASS\->_num(OBJ) 4
511 .IX Item "CLASS->_num(OBJ)"
512 Returns a Perl scalar number representing the number OBJ as close as
513 possible. Since Perl scalars have limited precision, the returned value might
514 not be exactly the same as OBJ.
515 .PP
516 \fIMiscellaneous\fR
517 .IX Subsection "Miscellaneous"
518 .IP CLASS\->_copy(OBJ) 4
519 .IX Item "CLASS->_copy(OBJ)"
520 Returns a true copy OBJ.
521 .IP CLASS\->_len(OBJ) 4
522 .IX Item "CLASS->_len(OBJ)"
523 Returns the number of the decimal digits in OBJ. The output is a Perl scalar.
524 .IP CLASS\->_zeros(OBJ) 4
525 .IX Item "CLASS->_zeros(OBJ)"
526 Returns the number of trailing decimal zeros. The output is a Perl scalar. The
527 number zero has no trailing decimal zeros.
528 .IP "CLASS\->_digit(OBJ, N)" 4
529 .IX Item "CLASS->_digit(OBJ, N)"
530 Returns the Nth digit in OBJ as a Perl scalar. N is a Perl scalar, where zero
531 refers to the rightmost (least significant) digit, and negative values count
532 from the left (most significant digit). If \f(CW$obj\fR represents the number 123, then
533 .Sp
534 .Vb 4
535 \& CLASS\->_digit($obj, 0) # returns 3
536 \& CLASS\->_digit($obj, 1) # returns 2
537 \& CLASS\->_digit($obj, 2) # returns 1
538 \& CLASS\->_digit($obj, \-1) # returns 1
539 .Ve
540 .IP CLASS\->_digitsum(OBJ) 4
541 .IX Item "CLASS->_digitsum(OBJ)"
542 Returns the sum of the base 10 digits.
543 .IP CLASS\->_check(OBJ) 4
544 .IX Item "CLASS->_check(OBJ)"
545 Returns true if the object is invalid and false otherwise. Preferably, the true
546 value is a string describing the problem with the object. This is a check
547 routine to test the internal state of the object for corruption.
548 .IP CLASS\->_set(OBJ) 4
549 .IX Item "CLASS->_set(OBJ)"
550 xxx
551 .SS "API version 2"
552 .IX Subsection "API version 2"
553 The following methods are required for an API version of 2 or greater.
554 .PP
555 \fIConstructors\fR
556 .IX Subsection "Constructors"
557 .IP CLASS\->_1ex(N) 4
558 .IX Item "CLASS->_1ex(N)"
559 Return an object representing the number 10**N where N >= 0 is a Perl
560 scalar.
561 .PP
562 \fIMathematical functions\fR
563 .IX Subsection "Mathematical functions"
564 .IP "CLASS\->_nok(OBJ1, OBJ2)" 4
565 .IX Item "CLASS->_nok(OBJ1, OBJ2)"
566 Return the binomial coefficient OBJ1 over OBJ1.
567 .PP
568 \fIMiscellaneous\fR
569 .IX Subsection "Miscellaneous"
570 .IP CLASS\->_alen(OBJ) 4
571 .IX Item "CLASS->_alen(OBJ)"
572 Return the approximate number of decimal digits of the object. The output is a
573 Perl scalar.
574 .SH "WRAP YOUR OWN"
575 .IX Header "WRAP YOUR OWN"
576 If you want to port your own favourite C library for big numbers to the
577 Math::BigInt interface, you can take any of the already existing modules as a
578 rough guideline. You should really wrap up the latest Math::BigInt and
579 Math::BigFloat testsuites with your module, and replace in them any of the
580 following:
581 .PP
582 .Vb 1
583 \& use Math::BigInt;
584 .Ve
585 .PP
586 by this:
587 .PP
588 .Vb 1
589 \& use Math::BigInt lib => \*(Aqyourlib\*(Aq;
590 .Ve
591 .PP
592 This way you ensure that your library really works 100% within Math::BigInt.
593 .SH BUGS
594 .IX Header "BUGS"
595 Please report any bugs or feature requests to
596 \&\f(CW\*(C`bug\-math\-bigint at rt.cpan.org\*(C'\fR, or through the web interface at
597 <https://rt.cpan.org/Ticket/Create.html?Queue=Math\-BigInt>
598 (requires login).
599 We will be notified, and then you\*(Aqll automatically be notified of progress on
600 your bug as I make changes.
601 .SH SUPPORT
602 .IX Header "SUPPORT"
603 You can find documentation for this module with the perldoc command.
604 .PP
605 .Vb 1
606 \& perldoc Math::BigInt::Calc
607 .Ve
608 .PP
609 You can also look for information at:
610 .IP \(bu 4
611 GitHub Source Repository
612 .Sp
613 <https://github.com/pjacklam/p5\-Math\-BigInt>
614 .IP \(bu 4
615 RT: CPAN\*(Aqs request tracker
616 .Sp
617 <https://rt.cpan.org/Public/Dist/Display.html?Name=Math\-BigInt>
618 .IP \(bu 4
619 MetaCPAN
620 .Sp
621 <https://metacpan.org/release/Math\-BigInt>
622 .IP \(bu 4
623 CPAN Testers Matrix
624 .Sp
625 <http://matrix.cpantesters.org/?dist=Math\-BigInt>
626 .SH LICENSE
627 .IX Header "LICENSE"
628 This program is free software; you may redistribute it and/or modify it under
629 the same terms as Perl itself.
630 .SH AUTHOR
631 .IX Header "AUTHOR"
632 Peter John Acklam, <[email protected]>
633 .PP
634 Code and documentation based on the Math::BigInt::Calc module by Tels
635 <nospam\[email protected]>
636 .SH "SEE ALSO"
637 .IX Header "SEE ALSO"
638 Math::BigInt, Math::BigInt::Calc, Math::BigInt::GMP,
639 Math::BigInt::FastCalc and Math::BigInt::Pari.