1 package Math::BigInt::Calc;
5 # use warnings; # dont use warnings for older Perls
8 use vars qw/@ISA $VERSION/;
13 # Package to store unsigned big integers in decimal and do math with them
15 # Internally the numbers are stored in an array with at least 1 element, no
16 # leading zero parts (except the first) and in base 1eX where X is determined
17 # automatically at loading time to be the maximum possible value
20 # - fully remove funky $# stuff (maybe)
22 # USE_MUL: due to problems on certain os (os390, posix-bc) "* 1e-5" is used
23 # instead of "/ 1e5" at some places, (marked with USE_MUL). Other platforms
24 # BS2000, some Crays need USE_DIV instead.
25 # The BEGIN block is used to determine which of the two variants gives the
28 ##############################################################################
29 # global constants, flags and accessory
31 # constants for easier life
33 my ($BASE,$RBASE,$BASE_LEN,$MAX_VAL);
37 # set/get the BASE_LEN and assorted other, connected values
38 # used only be the testsuite, set is used only by the BEGIN block below
42 $b = 8 if $b > 8; # cap, for VMS, OS/390 and other 64 bit
44 $BASE = int("1e".$BASE_LEN);
45 $RBASE = abs('1e-'.$BASE_LEN); # see USE_MUL
47 # print "BASE_LEN: $BASE_LEN MAX_VAL: $MAX_VAL\n";
48 # print "int: ",int($BASE * $RBASE),"\n";
49 if (int($BASE * $RBASE) == 0) # should be 1
52 *{_mul} = \&_mul_use_mul;
53 *{_div} = \&_div_use_mul;
58 *{_mul} = \&_mul_use_div;
59 *{_div} = \&_div_use_div;
67 # from Daniel Pfeiffer: determine largest group of digits that is precisely
68 # multipliable with itself plus carry
69 # Test now changed to expect the proper pattern, not a result off by 1 or 2
70 my ($e, $num) = 3; # lowest value we will use is 3+1-1 = 3
73 $num = ('9' x ++$e) + 0;
76 } while ("$num" =~ /9{$e}0{$e}/); # must be a certain pattern
77 # last test failed, so retract one step:
81 ##############################################################################
82 # create objects from various representations
86 # (string) return ref to num_array
87 # Convert a number from string format to internal base 100000 format.
88 # Assumes normalized value as input.
90 my $il = CORE::length($$d)-1;
91 # these leaves '00000' instead of int 0 and will be corrected after any op
92 return [ reverse(unpack("a" . ($il % $BASE_LEN+1)
93 . ("a$BASE_LEN" x ($il / $BASE_LEN)), $$d)) ];
110 # create a two (for _pow)
119 # catch and throw away
122 ##############################################################################
123 # convert back to string and number
127 # (ref to BINT) return num_str
128 # Convert number from internal base 100000 format to string format.
129 # internal format is always normalized (no leading zeros, "-0" => "+0")
132 my $l = scalar @$ar; # number of parts
133 return $nan if $l < 1; # should not happen
134 # handle first one different to strip leading zeros from it (there are no
135 # leading zero parts in internal representation)
136 $l --; $ret .= $ar->[$l]; $l--;
137 # Interestingly, the pre-padd method uses more time
138 # the old grep variant takes longer (14 to 10 sec)
139 my $z = '0' x ($BASE_LEN-1);
142 $ret .= substr($z.$ar->[$l],-$BASE_LEN); # fastest way I could think of
150 # Make a number (scalar int/float) from a BigInt object
152 return $x->[0] if scalar @$x == 1; # below $BASE
157 $num += $fac*$_; $fac *= $BASE;
162 ##############################################################################
167 # (ref to int_num_array, ref to int_num_array)
168 # routine to add two base 1eX numbers
169 # stolen from Knuth Vol 2 Algorithm A pg 231
170 # there are separate routines to add and sub as per Knuth pg 233
171 # This routine clobbers up array x, but not y.
175 # for each in Y, add Y to X and carry. If after that, something is left in
176 # X, foreach in X add carry to X and then return X, carry
177 # Trades one "$j++" for having to shift arrays, $j could be made integer
178 # but this would impose a limit to number-length of 2**32.
179 my $i; my $car = 0; my $j = 0;
182 $x->[$j] -= $BASE if $car = (($x->[$j] += $i + $car) >= $BASE) ? 1 : 0;
187 $x->[$j] -= $BASE if $car = (($x->[$j] += $car) >= $BASE) ? 1 : 0; $j++;
194 # (ref to int_num_array, ref to int_num_array)
195 # routine to add 1 to a base 1eX numbers
196 # This routine clobbers up array x, but not y.
201 return $x if (($i += 1) < $BASE); # early out
204 if ($x->[-1] == 0) # last overflowed
213 # (ref to int_num_array, ref to int_num_array)
214 # routine to add 1 to a base 1eX numbers
215 # This routine clobbers up array x, but not y.
220 last if (($i -= 1) >= 0); # early out
223 pop @$x if $x->[-1] == 0 && @$x > 1; # last overflowed (but leave 0)
229 # (ref to int_num_array, ref to int_num_array)
230 # subtract base 1eX numbers -- stolen from Knuth Vol 2 pg 232, $x > $y
231 # subtract Y from X (X is always greater/equal!) by modifying x in place
232 my ($c,$sx,$sy,$s) = @_;
234 my $car = 0; my $i; my $j = 0;
240 last unless defined $sy->[$j] || $car;
241 $i += $BASE if $car = (($i -= ($sy->[$j] || 0) + $car) < 0); $j++;
243 # might leave leading zeros, so fix that
249 #print "case 1 (swap)\n";
252 last unless defined $sy->[$j] || $car;
254 if $car = (($sy->[$j] = $i-($sy->[$j]||0) - $car) < 0);
257 # might leave leading zeros, so fix that
265 # (BINT, BINT) return nothing
266 # multiply two numbers in internal representation
267 # modifies first arg, second need not be different from first
268 my ($c,$xv,$yv) = @_;
270 my @prod = (); my ($prod,$car,$cty,$xi,$yi);
271 # since multiplying $x with $x fails, make copy in this case
272 $yv = [@$xv] if "$xv" eq "$yv"; # same references?
280 # $prod = $xi * $yi + ($prod[$cty] || 0) + $car;
282 # $prod - ($car = int($prod * RBASE)) * $BASE; # see USE_MUL
284 # $prod[$cty] += $car if $car; # need really to check for 0?
288 # looping through this if $xi == 0 is silly - so optimize it away!
289 $xi = (shift @prod || 0), next if $xi == 0;
292 $prod = $xi * $yi + ($prod[$cty] || 0) + $car;
293 ## this is actually a tad slower
294 ## $prod = $prod[$cty]; $prod += ($car + $xi * $yi); # no ||0 here
296 $prod - ($car = int($prod * $RBASE)) * $BASE; # see USE_MUL
298 $prod[$cty] += $car if $car; # need really to check for 0?
299 $xi = shift @prod || 0; # || 0 makes v5.005_3 happy
303 # normalize (handled last to save check for $y->is_zero()
309 # (BINT, BINT) return nothing
310 # multiply two numbers in internal representation
311 # modifies first arg, second need not be different from first
312 my ($c,$xv,$yv) = @_;
314 my @prod = (); my ($prod,$car,$cty,$xi,$yi);
315 # since multiplying $x with $x fails, make copy in this case
316 $yv = [@$xv] if "$xv" eq "$yv"; # same references?
320 # looping through this if $xi == 0 is silly - so optimize it away!
321 $xi = (shift @prod || 0), next if $xi == 0;
324 $prod = $xi * $yi + ($prod[$cty] || 0) + $car;
326 $prod - ($car = int($prod / $BASE)) * $BASE;
328 $prod[$cty] += $car if $car; # need really to check for 0?
329 $xi = shift @prod || 0; # || 0 makes v5.005_3 happy
333 # normalize (handled last to save check for $y->is_zero()
339 # ref to array, ref to array, modify first array and return remainder if
341 # no longer handles sign
342 my ($c,$x,$yorg) = @_;
343 my ($car,$bar,$prd,$dd,$xi,$yi,@q,$v2,$v1);
345 my (@d,$tmp,$q,$u2,$u1,$u0);
347 $car = $bar = $prd = 0;
350 if (($dd = int($BASE/($y->[-1]+1))) != 1)
354 $xi = $xi * $dd + $car;
355 $xi -= ($car = int($xi * $RBASE)) * $BASE; # see USE_MUL
357 push(@$x, $car); $car = 0;
360 $yi = $yi * $dd + $car;
361 $yi -= ($car = int($yi * $RBASE)) * $BASE; # see USE_MUL
368 @q = (); ($v2,$v1) = @$y[-2,-1];
372 ($u2,$u1,$u0) = @$x[-3..-1];
374 #warn "oups v1 is 0, u0: $u0 $y->[-2] $y->[-1] l ",scalar @$y,"\n"
376 # $q = (($u0 == $v1) ? 99999 : int(($u0*$BASE+$u1)/$v1));
377 $q = (($u0 == $v1) ? $MAX_VAL : int(($u0*$BASE+$u1)/$v1));
378 --$q while ($v2*$q > ($u0*$BASE+$u1-$q*$v1)*$BASE+$u2);
381 ($car, $bar) = (0,0);
382 for ($yi = 0, $xi = $#$x-$#$y-1; $yi <= $#$y; ++$yi,++$xi)
384 $prd = $q * $y->[$yi] + $car;
385 $prd -= ($car = int($prd * $RBASE)) * $BASE; # see USE_MUL
386 $x->[$xi] += $BASE if ($bar = (($x->[$xi] -= $prd + $bar) < 0));
388 if ($x->[-1] < $car + $bar)
391 for ($yi = 0, $xi = $#$x-$#$y-1; $yi <= $#$y; ++$yi,++$xi)
394 if ($car = (($x->[$xi] += $y->[$yi] + $car) > $BASE));
398 pop(@$x); unshift(@q, $q);
406 for $xi (reverse @$x)
408 $prd = $car * $BASE + $xi;
409 $car = $prd - ($tmp = int($prd / $dd)) * $dd; # see USE_MUL
429 # ref to array, ref to array, modify first array and return remainder if
431 # no longer handles sign
432 my ($c,$x,$yorg) = @_;
433 my ($car,$bar,$prd,$dd,$xi,$yi,@q,$v2,$v1);
435 my (@d,$tmp,$q,$u2,$u1,$u0);
437 $car = $bar = $prd = 0;
440 if (($dd = int($BASE/($y->[-1]+1))) != 1)
444 $xi = $xi * $dd + $car;
445 $xi -= ($car = int($xi / $BASE)) * $BASE;
447 push(@$x, $car); $car = 0;
450 $yi = $yi * $dd + $car;
451 $yi -= ($car = int($yi / $BASE)) * $BASE;
458 @q = (); ($v2,$v1) = @$y[-2,-1];
462 ($u2,$u1,$u0) = @$x[-3..-1];
464 #warn "oups v1 is 0, u0: $u0 $y->[-2] $y->[-1] l ",scalar @$y,"\n"
466 # $q = (($u0 == $v1) ? 99999 : int(($u0*$BASE+$u1)/$v1));
467 $q = (($u0 == $v1) ? $MAX_VAL : int(($u0*$BASE+$u1)/$v1));
468 --$q while ($v2*$q > ($u0*$BASE+$u1-$q*$v1)*$BASE+$u2);
471 ($car, $bar) = (0,0);
472 for ($yi = 0, $xi = $#$x-$#$y-1; $yi <= $#$y; ++$yi,++$xi)
474 $prd = $q * $y->[$yi] + $car;
475 $prd -= ($car = int($prd / $BASE)) * $BASE;
476 $x->[$xi] += $BASE if ($bar = (($x->[$xi] -= $prd + $bar) < 0));
478 if ($x->[-1] < $car + $bar)
481 for ($yi = 0, $xi = $#$x-$#$y-1; $yi <= $#$y; ++$yi,++$xi)
484 if ($car = (($x->[$xi] += $y->[$yi] + $car) > $BASE));
488 pop(@$x); unshift(@q, $q);
496 for $xi (reverse @$x)
498 $prd = $car * $BASE + $xi;
499 $car = $prd - ($tmp = int($prd / $dd)) * $dd;
519 # if possible, use mod shortcut
522 # slow way since $y to big
525 my ($xo,$rem) = _div($c,$x,$yo);
529 # both are single element arrays
536 # @y is single element, but @x has more than one
540 # when BASE % Y == 0 then (B * BASE) % Y == 0
541 # (B * BASE) % $y + A % Y => A % Y
542 # so need to consider only last element: O(1)
547 # else need to go trough all elements: O(N), but loop is a bit simplified
559 # else need to go trough all elements: O(N)
560 my $r = 0; my $bm = 1;
563 $r += ($_ % $y) * $bm;
575 ##############################################################################
580 my ($c,$x,$y,$n) = @_;
584 return; # we cant do this here, due to now _pow, so signal failure
588 # shortcut (faster) for shifting by 10)
589 # multiples of $BASE_LEN
590 my $dst = 0; # destination
591 my $src = _num($c,$y); # as normal int
592 my $rem = $src % $BASE_LEN; # remainder to shift
593 $src = int($src / $BASE_LEN); # source
596 splice (@$x,0,$src); # even faster, 38.4 => 39.3
600 my $len = scalar @$x - $src; # elems to go
601 my $vd; my $z = '0'x $BASE_LEN;
602 $x->[scalar @$x] = 0; # avoid || 0 test inside loop
606 $vd = substr($vd,-$BASE_LEN,$BASE_LEN-$rem);
608 $vd = substr($z.$x->[$src],-$rem,$rem) . $vd;
609 $vd = substr($vd,-$BASE_LEN,$BASE_LEN) if length($vd) > $BASE_LEN;
610 $x->[$dst] = int($vd);
613 splice (@$x,$dst) if $dst > 0; # kill left-over array elems
614 pop @$x if $x->[-1] == 0; # kill last element if 0
622 my ($c,$x,$y,$n) = @_;
626 return; # we cant do this here, due to now _pow, so signal failure
630 # shortcut (faster) for shifting by 10) since we are in base 10eX
631 # multiples of $BASE_LEN:
632 my $src = scalar @$x; # source
633 my $len = _num($c,$y); # shift-len as normal int
634 my $rem = $len % $BASE_LEN; # remainder to shift
635 my $dst = $src + int($len/$BASE_LEN); # destination
636 my $vd; # further speedup
637 $x->[$src] = 0; # avoid first ||0 for speed
638 my $z = '0' x $BASE_LEN;
641 $vd = $x->[$src]; $vd = $z.$vd;
642 $vd = substr($vd,-$BASE_LEN+$rem,$BASE_LEN-$rem);
643 $vd .= $src > 0 ? substr($z.$x->[$src-1],-$BASE_LEN,$rem) : '0' x $rem;
644 $vd = substr($vd,-$BASE_LEN,$BASE_LEN) if length($vd) > $BASE_LEN;
645 $x->[$dst] = int($vd);
648 # set lowest parts to 0
649 while ($dst >= 0) { $x->[$dst--] = 0; }
650 # fix spurios last zero element
651 splice @$x,-1 if $x->[-1] == 0;
659 # ref to array, ref to array, return ref to array
660 my ($c,$cx,$cy) = @_;
664 my $y1 = _copy($c,$cy);
665 while (!_is_one($c,$y1))
667 _mul($c,$pow2,$cx) if _is_odd($c,$y1);
671 _mul($c,$cx,$pow2) unless _is_one($c,$pow2);
675 ##############################################################################
680 # internal absolute post-normalized compare (ignore signs)
681 # ref to array, ref to array, return <0, 0, >0
682 # arrays must have at least one entry; this is not checked for
684 my ($c,$cx, $cy) = @_;
687 # calculate length based on digits, not parts
688 $x = _len('',$cx); $y = _len('',$cy);
689 my $lxy = $x - $y; # if different in length
690 return -1 if $lxy < 0;
691 return 1 if $lxy > 0;
693 # first way takes 5.49 sec instead of 4.87, but has the early out advantage
694 # so grep is slightly faster, but more inflexible. hm. $_ instead of $k
695 # yields 5.6 instead of 5.5 sec huh?
696 # manual way (abort if unequal, good for early ne)
697 my $j = scalar @$cx - 1;
700 # print "$cx->[$j] $cy->[$j] $a",$cx->[$j]-$cy->[$j],"\n";
701 last if ($a = $cx->[$j] - $cy->[$j]); $j--;
706 # while it early aborts, it is even slower than the manual variant
707 #grep { return $a if ($a = $_ - $cy->[$i++]); } @$cx;
708 # grep way, go trough all (bad for early ne)
709 #grep { $a = $_ - $cy->[$i++]; } @$cx;
715 # compute number of digits in bigint, minus the sign
716 # int() because add/sub sometimes leaves strings (like '00005') instead of
717 # int ('5') in this place, thus causing length() to report wrong length
720 return (@$cx-1)*$BASE_LEN+length(int($cx->[-1]));
725 # return the nth digit, negative values count backward
726 # zero is rightmost, so _digit(123,0) will give 3
729 my $len = _len('',$x);
731 $n = $len+$n if $n < 0; # -1 last, -2 second-to-last
732 $n = abs($n); # if negative was too big
733 $len--; $n = $len if $n > $len; # n to big?
735 my $elem = int($n / $BASE_LEN); # which array element
736 my $digit = $n % $BASE_LEN; # which digit in this element
737 $elem = '0000'.@$x[$elem]; # get element padded with 0's
738 return substr($elem,-$digit-1,1);
743 # return amount of trailing zeros in decimal
744 # check each array elem in _m for having 0 at end as long as elem == 0
745 # Upon finding a elem != 0, stop
747 my $zeros = 0; my $elem;
752 $elem = "$e"; # preserve x
753 $elem =~ s/.*?(0*$)/$1/; # strip anything not zero
754 $zeros *= $BASE_LEN; # elems * 5
755 $zeros += CORE::length($elem); # count trailing zeros
758 $zeros ++; # real else branch: 50% slower!
763 ##############################################################################
768 # return true if arg (BINT or num_str) is zero (array '+', '0')
770 return (((scalar @$x == 1) && ($x->[0] == 0))) <=> 0;
775 # return true if arg (BINT or num_str) is even
777 return (!($x->[0] & 1)) <=> 0;
782 # return true if arg (BINT or num_str) is even
784 return (($x->[0] & 1)) <=> 0;
789 # return true if arg (BINT or num_str) is one (array '+', '1')
791 return (scalar @$x == 1) && ($x->[0] == 1) <=> 0;
796 # internal normalization function that strips leading zeros from the array
800 my $cnt = scalar @$s; # get count of parts
802 #print "strip: cnt $cnt i $i\n";
803 # '0', '3', '4', '0', '0',
808 # => fcnt = cnt - i (5-2 => 3, cnt => 5-1 = 4, throw away from 4th pos)
809 # >= 1: skip first part (this can be zero)
810 while ($i > 0) { last if $s->[$i] != 0; $i--; }
811 $i++; splice @$s,$i if ($i < $cnt); # $i cant be 0
815 ###############################################################################
816 # check routine to test internal state of corruptions
820 # used by the test suite
823 return "$x is not a reference" if !ref($x);
825 # are all parts are valid?
826 my $i = 0; my $j = scalar @$x; my ($e,$try);
829 $e = $x->[$i]; $e = 'undef' unless defined $e;
830 $try = '=~ /^[\+]?[0-9]+\$/; '."($x, $e)";
831 last if $e !~ /^[+]?[0-9]+$/;
832 $try = '=~ /^[\+]?[0-9]+\$/; '."($x, $e) (stringify)";
833 last if "$e" !~ /^[+]?[0-9]+$/;
834 $try = '=~ /^[\+]?[0-9]+\$/; '."($x, $e) (cat-stringify)";
835 last if '' . "$e" !~ /^[+]?[0-9]+$/;
836 $try = ' < 0 || >= $BASE; '."($x, $e)";
837 last if $e <0 || $e >= $BASE;
838 # this test is disabled, since new/bnorm and certain ops (like early out
839 # in add/sub) are allowed/expected to leave '00000' in some elements
840 #$try = '=~ /^00+/; '."($x, $e)";
841 #last if $e =~ /^00+/;
844 return "Illegal part '$e' at pos $i (tested: $try)" if $i < $j;
853 Math::BigInt::Calc - Pure Perl module to support Math::BigInt
857 Provides support for big integer calculations. Not intended to be used by other
858 modules (except Math::BigInt::Cached). Other modules which sport the same
859 functions can also be used to support Math::Bigint, like Math::BigInt::Pari.
863 In order to allow for multiple big integer libraries, Math::BigInt was
864 rewritten to use library modules for core math routines. Any module which
865 follows the same API as this can be used instead by using the following:
867 use Math::BigInt lib => 'libname';
869 'libname' is either the long name ('Math::BigInt::Pari'), or only the short
874 The following functions MUST be defined in order to support the use by
877 _new(string) return ref to new object from ref to decimal string
878 _zero() return a new object with value 0
879 _one() return a new object with value 1
881 _str(obj) return ref to a string representing the object
882 _num(obj) returns a Perl integer/floating point number
883 NOTE: because of Perl numeric notation defaults,
884 the _num'ified obj may lose accuracy due to
885 machine-dependend floating point size limitations
887 _add(obj,obj) Simple addition of two objects
888 _mul(obj,obj) Multiplication of two objects
889 _div(obj,obj) Division of the 1st object by the 2nd
890 In list context, returns (result,remainder).
891 NOTE: this is integer math, so no
892 fractional part will be returned.
893 _sub(obj,obj) Simple subtraction of 1 object from another
894 a third, optional parameter indicates that the params
895 are swapped. In this case, the first param needs to
896 be preserved, while you can destroy the second.
897 sub (x,y,1) => return x - y and keep x intact!
898 _dec(obj) decrement object by one (input is garant. to be > 0)
899 _inc(obj) increment object by one
902 _acmp(obj,obj) <=> operator for objects (return -1, 0 or 1)
904 _len(obj) returns count of the decimal digits of the object
905 _digit(obj,n) returns the n'th decimal digit of object
907 _is_one(obj) return true if argument is +1
908 _is_zero(obj) return true if argument is 0
909 _is_even(obj) return true if argument is even (0,2,4,6..)
910 _is_odd(obj) return true if argument is odd (1,3,5,7..)
912 _copy return a ref to a true copy of the object
914 _check(obj) check whether internal representation is still intact
915 return 0 for ok, otherwise error message as string
917 The following functions are optional, and can be defined if the underlying lib
918 has a fast way to do them. If undefined, Math::BigInt will use pure Perl (hence
919 slow) fallback routines to emulate these:
921 _from_hex(str) return ref to new object from ref to hexadecimal string
922 _from_bin(str) return ref to new object from ref to binary string
924 _as_hex(str) return ref to scalar string containing the value as
925 unsigned hex string, with the '0x' prepended.
926 Leading zeros must be stripped.
927 _as_bin(str) Like as_hex, only as binary string containing only
928 zeros and ones. Leading zeros must be stripped and a
929 '0b' must be prepended.
931 _rsft(obj,N,B) shift object in base B by N 'digits' right
932 For unsupported bases B, return undef to signal failure
933 _lsft(obj,N,B) shift object in base B by N 'digits' left
934 For unsupported bases B, return undef to signal failure
936 _xor(obj1,obj2) XOR (bit-wise) object 1 with object 2
937 Note: XOR, AND and OR pad with zeros if size mismatches
938 _and(obj1,obj2) AND (bit-wise) object 1 with object 2
939 _or(obj1,obj2) OR (bit-wise) object 1 with object 2
941 _mod(obj,obj) Return remainder of div of the 1st by the 2nd object
942 _sqrt(obj) return the square root of object
943 _pow(obj,obj) return object 1 to the power of object 2
944 _gcd(obj,obj) return Greatest Common Divisor of two objects
946 _zeros(obj) return number of trailing decimal zeros
948 Input strings come in as unsigned but with prefix (i.e. as '123', '0xabc'
951 Testing of input parameter validity is done by the caller, so you need not
952 worry about underflow (f.i. in C<_sub()>, C<_dec()>) nor about division by
953 zero or similar cases.
955 The first parameter can be modified, that includes the possibility that you
956 return a reference to a completely different object instead. Although keeping
957 the reference and just changing it's contents is prefered over creating and
958 returning a different reference.
960 Return values are always references to objects or strings. Exceptions are
961 C<_lsft()> and C<_rsft()>, which return undef if they can not shift the
962 argument. This is used to delegate shifting of bases different than the one
963 you can support back to Math::BigInt, which will use some generic code to
964 calculate the result.
968 If you want to port your own favourite c-lib for big numbers to the
969 Math::BigInt interface, you can take any of the already existing modules as
970 a rough guideline. You should really wrap up the latest BigInt and BigFloat
971 testsuites with your module, and replace in them any of the following:
977 use Math::BigInt lib => 'yourlib';
979 This way you ensure that your library really works 100% within Math::BigInt.
983 This program is free software; you may redistribute it and/or modify it under
984 the same terms as Perl itself.
988 Original math code by Mark Biggar, rewritten by Tels L<http://bloodgate.com/>
990 Seperated from BigInt and shaped API with the help of John Peacock.
994 L<Math::BigInt>, L<Math::BigFloat>, L<Math::BigInt::BitVect>,
995 L<Math::BigInt::GMP>, L<Math::BigInt::Cached> and L<Math::BigInt::Pari>.