Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) Standard preamble: ========================================================================
NAMEMath::BigInt::Lib - virtual parent class for Math::BigInt libraries
SYNOPSISThis 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. Backend libraries include Math::BigInt::Calc, Math::BigInt::FastCalc, Math::BigInt::GMP, Math::BigInt::Pari and others.
DESCRIPTIONIn 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
use Math::BigInt lib => 'libname';
'libname' is either the long name, like 'Math::BigInt::Pari', or only the short version, like 'Pari'.
General NotesA 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 "_sub()" and "_dec()") nor about division by zero (e.g., in "_div()") or similar cases.
Some libraries use methods that don't modify their argument, and some libraries don't even use objects. Because of this, liberary methods are always called as class methods, not instance methods:
$x = Class -> method($x, $y); # like this $x = $x -> method($y); # not like this ... $x -> method($y); # ... or like this
And with boolean methods
$bool = Class -> method($x, $y); # like this $bool = $x -> method($y); # not like this ...
Return values are always objects, strings, Perl scalars, or true/false for comparison routines.
Return APIversion as a Perl scalar, 1 for Math::BigInt v1.70, 2 for Math::BigInt v1.83.
This method is no longer used. Methods that are not implemented by a subclass will be inherited from this class.
The following methods are mandatory: _new(), _str(), _add(), and _sub(). However, computations will be very slow without _mul() and _div().
- Convert a string representing an unsigned decimal number to an object representing the same number. The input is normalize, i.e., it matches "^(0|[1-9]\d*)$".
- Return an object representing the number zero.
- Return an object representing the number one.
- Return an object representing the number two.
- Return an object representing the number ten.
- Return an object given a string representing a binary number. The input has a '0b' prefix and matches the regular expression "^0[bB](0|1*)$".
- Return an object given a string representing an octal number. The input has a '0' prefix and matches the regular expression "^0[1-7]*$".
- Return an object given a string representing a hexadecimal number. The input has a '0x' prefix and matches the regular expression "^0x(0|[1-9a-fA-F][\da-fA-F]*)$".
- 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 ``\x01\x00'' should give an output value representing the number 256.
- _add(OBJ1, OBJ2)
Returns the result of adding OBJ2toOBJ1.
- _mul(OBJ1, OBJ2)
Returns the result of multiplying OBJ2andOBJ1.
- _div(OBJ1, OBJ2)
Returns the result of dividing OBJ1byOBJ2and truncating the result to an integer.
- _sub(OBJ1, OBJ2, FLAG)
- _sub(OBJ1, OBJ2)
Returns the result of subtracting OBJ2byOBJ1.If "flag" is false or omitted,OBJ1might be modified. If "flag" is true,OBJ2might be modified.
Decrement OBJby one.
Increment OBJby one.
- _mod(OBJ1, OBJ2)
Return OBJ1moduloOBJ2,i.e., the remainder after dividingOBJ1byOBJ2.
- Return the square root of the object, truncated to integer.
- _root(OBJ, N)
- Return Nth root of the object, truncated to int. N is >= 3.
- Return factorial of object (1*2*3*4*...).
- _pow(OBJ1, OBJ2)
Return OBJ1to the power ofOBJ2.By convention, 0**0 = 1.
- _modinv(OBJ1, OBJ2)
Return modular multiplicative inverse, i.e., return OBJ3so that
(OBJ3 * OBJ1) % OBJ2 = 1 % OBJ2
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 (``+'' or ``-'').
The output value, with its sign, must either be a positive value in the range 1,2,...,OBJ2-1 or the same value subtractedOBJ2.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 ``+'' sign, since (3*7) % 5 = 1 % 5, or an object representing the number 2 and ``-'' sign, since (-2*7) % 5 = 1 % 5.
- _modpow(OBJ1, OBJ2, OBJ3)
Return modular exponentiation, (OBJ1**OBJ2) %OBJ3.
- _rsft(OBJ, N, B)
Shift object N digits right in base B and return the resulting object. This is
equivalent to performing integer division by B**N and discarding the remainder,
except that it might be much faster, depending on how the number is represented
For instance, if the object $obj represents the hexadecimal number 0xabcde, then "_rsft($obj, 2, 16)" returns an object representing the number 0xabc. The ``remainer'', 0xde, is discarded and not returned.
- _lsft(OBJ, N, B)
- Shift the object N digits left in base B. This is equivalent to multiplying by B**N, except that it might be much faster, depending on how the number is represented internally.
- _log_int(OBJ, B)
Return integer log of OBJto baseBASE.This method has two output arguments, theOBJECTand aSTATUS.TheSTATUSis Perl scalar; it is 1 ifOBJis the exact result, 0 if the result was truncted to giveOBJ,and undef if it is unknown whetherOBJis the exact result.
- _gcd(OBJ1, OBJ2)
Return the greatest common divisor of OBJ1andOBJ2.
- _lcm(OBJ1, OBJ2)
Return the least common multiple of OBJ1andOBJ2.
Each of these methods may modify the first input argument.
- _and(OBJ1, OBJ2)
- Return bitwise and. If necessary, the smallest number is padded with leading zeros.
- _or(OBJ1, OBJ2)
- Return bitwise or. If necessary, the smallest number is padded with leading zeros.
- _xor(OBJ1, OBJ2)
- Return bitwise exclusive or. If necessary, the smallest number is padded with leading zeros.
Returns a true value if OBJis zero, and false value otherwise.
Returns a true value if OBJis one, and false value otherwise.
Returns a true value if OBJis two, and false value otherwise.
Returns a true value if OBJis ten, and false value otherwise.
Return a true value if OBJis an even integer, and a false value otherwise.
Return a true value if OBJis an even integer, and a false value otherwise.
- _acmp(OBJ1, OBJ2)
Compare OBJ1andOBJ2and return -1, 0, or 1, ifOBJ1is less than, equal to, or larger thanOBJ2,respectively.
- Return a string representing the object. The returned string should have no leading zeros, i.e., it should match "^(0|[1-9]\d*)$".
- Return the binary string representation of the number. The string must have a '0b' prefix.
Return the octal string representation of the number. The string must have
a '0x' prefix.
Note: This method was required from Math::BigInt version 1.78, but the requiredAPIversion number was not incremented, so there are older libraries that supportAPIversion 1, but do not support "_as_oct()".
- Return the hexadecimal string representation of the number. The string must have a '0x' prefix.
- Return a byte string representation of the number. The byte string is in big endian byte order, so if the object represents the number 256, the output should be the two-byte string ``\x01\x00''.
- Given an object, return a Perl scalar number (int/float) representing this number.
- Return a true copy of the object.
- Returns the number of the decimal digits in the number. The output is a Perl scalar.
- Return the number of trailing decimal zeros. The output is a Perl scalar.
- _digit(OBJ, N)
- Return the Nth digit 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 $obj represents the number 123, then $obj-_digit(0)> is 3 and _digit(123, -1) is 1.
- Return 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.
API version 2
The following methods are required for an
- Return an object representing the number 10**N where N >= 0 is a Perl scalar.
- _nok(OBJ1, OBJ2)
Return the binomial coefficient OBJ1overOBJ1.
- Return the approximate number of decimal digits of the object. The output is a Perl scalar.
API optional methods
The following methods are optional, and can be defined if the underlying lib
has a fast way to do them. If undefined, Math::BigInt will use pure Perl (hence
slow) fallback routines to emulate these:
Signed bitwise operators.
- _signed_or(OBJ1, OBJ2, SIGN1, SIGN2)
- Return the signed bitwise or.
- _signed_and(OBJ1, OBJ2, SIGN1, SIGN2)
- Return the signed bitwise and.
- _signed_xor(OBJ1, OBJ2, SIGN1, SIGN2)
- Return the signed bitwise exclusive or.
WRAP YOUR OWNIf 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:
use Math::BigInt lib => 'yourlib';
This way you ensure that your library really works 100% within Math::BigInt.
BUGSPlease report any bugs or feature requests to "bug-math-bigint at rt.cpan.org", or through the web interface at <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.
SUPPORTYou can find documentation for this module with the perldoc command.
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPANdocumentation
The Bignum mailing list
LICENSEThis program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
AUTHORPeter John Acklam, <email@example.com>
Code and documentation based on the Math::BigInt::Calc module by Tels <firstname.lastname@example.org>