Math::BigInt::Calc - Pure Perl module to support Math::BigInt
This library provides support for big integer calculations. It is not intended to be used by other modules. Other modules which support the same API (see below) can also be used to support Math::BigInt, like Math::BigInt::GMP and Math::BigInt::Pari.
In this library, the numbers are represented in base B = 10**N, where N is the largest possible value that does not cause overflow in the intermediate computations. The base B elements are stored in an array, with the least significant element stored in array element zero. There are no leading zero elements, except a single zero element when the number is zero.
For instance, if B = 10000, the number 1234567890 is represented internally as [3456, 7890, 12].
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 API can be used by Math::BigInt by using this in your program:
use Math::BigInt lib => 'libname';
'libname' is either the long name, like 'Math::BigInt::Pari', or only the short version, like 'Pari'.
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 _sub()
and _dec()
) nor about division by zero (e.g., in _div()
) or similar cases.
For some methods, the first parameter can be modified. That includes the possibility that you return a reference to a completely different object instead. Although keeping the reference and just changing its contents is preferred over creating and returning a different reference.
Return values are always objects, strings, Perl scalars, or true/false for comparison routines.
The following methods must be defined in order to support the use by Math::BigInt v1.70 or later.
Return API version as a Perl scalar, 1 for Math::BigInt v1.70, 2 for Math::BigInt v1.83.
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[01]*)$
.