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