| Previous
| Next
Math::BigInt::Calc
Supports big integer calculations. Math::BigInt::Calc allows you to use library modules for core math routines. This module is shipped with the Perl 5.8 source kit.
If you've written a module that uses the same API as Math::BigInt, you can use Math::BigInt::Calc as follows:
use Math::BigInt lib => 'yourlibname'; use Math::BigInt lib => 'Math::BigInt::yourlibname';
Math::BigInt exports the following functions, which must be defined in your module so Math::BigInt can support it:
_new(string)
- Returns a reference to new object from reference to decimal string.
_zero()
- Returns a new object with value .
_one()
- Returns a new object with value .
_str(obj)
- Returns a reference to a string representing the object.
_num(obj)
- Returns a Perl integer or floating-point number. This may not necessarily be accurate, depending on machine-dependent, floating-point size limitations.
_add(obj obj)
- Allows simple addition of two objects.
_mul(obj obj)
- Allows multiplication of two objects.
_div(obj obj)
- Implements division of the first object by the second. In a list context,
div() returns result, remainder.
_sub(obj obj)
- Implements simple subtraction of one object from another. A third, optional parameter indicates that the parameters are swapped.
_dec(obj)
- Decrements object by one.
_inc(obj)
- Increments object by one.
_acmp(obj obj)
- The
<=> operator for objects, which returns -1, , or .
_len(obj)
- Returns count of the decimal digits of the object.
_digit(obj n)
- Returns the
nth decimal digit of object.
_is_one(obj)
- Returns true if argument is .
_is_zero(obj)
- Returns true if the argument is .
_is_even(obj)
- Returns true if argument is even.
_is_odd(obj)
- Returns true if argument is odd.
_copy()
- Returns a reference to a true copy of the object.
_check(obj)
- Checks whether the internal representation is still intact. Returns for OK or an error message as a string.
The following functions are optional and can be defined if the underlying library can do them quickly. If undefined, Math::BigInt will use pure Perl fallback routines to emulate these. Note that falling back to Perl's routines will cause a performance hit.
_from_hex(string)
- Returns a reference to a new object from a reference to a hexadecimal string.
_from_bin(string)
- Returns a reference to a new object from a reference to a binary string.
_as_hex(string)
- Returns a reference to a scalar string containing the value as an unsigned hex string.
_as_hex() prepends the x, although you must strip all leading zeros.
_as_bin(string)
- Similar to
_as_hex(), except that it takes a binary string that contains only zeros and ones.
_rsft(obj n b)
- Shifts object (right) in base
B by n digits. Returns undef on failure.
_lsft(obj n b)
- Shifts object in base
b by n digits. Returns undef on failure.
_xor(obj1 obj2)
- Does an XOR of object 1 with object 2.
_and(obj1 obj2)
- Does an AND of object 1 with object 2.
_or(obj1 obj2)
- Does an OR of object 1 with object 2.
_mod(obj1 obj2)
- Returns remainder of division of the first object by the second object.
_sqrt(obj)
- Returns the square root of the object.
_fac(obj)
- Returns. factorial of object.
_pow(obj1 obj2)
- Returns object 1 to the power of object 2.
_gcd(obj1 obj2)
- Returns the greatest common divisor of two objects.
_zeros(obj)
- Returns the number of trailing decimal zeros.
|