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
0
._one()
Returns a new object with value
1
._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()
returnsresult
,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
,0
, or1
._len(
obj
)
Returns count of the decimal digits of the object.
_digit(
obj
,
n
)
Returns the
Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.