NAME
Math::BigInt::Calc - Pure Perl module to support Math::BigInt
SYNOPSIS
Provides support for big integer calculations. Not intended to be used by other modules. Other modules which export the same functions can also be used to support Math::Bigint
DESCRIPTION
In order to allow for multiple big integer libraries, Math::BigInt was rewritten to use library modules for core math routines. Any module which follows the same API as this can be used instead by using the following call:
use Math::BigInt Calc => BigNum;
EXPORT
The following functions MUST be exported in order to support the use by Math::BigInt:
_new(string) return ref to new object from ref to decimal string
_zero() return a new object with value 0
_one() return a new object with value 1
_str(obj) return ref to a string representing the object
_num(obj) returns a Perl integer/floating point number
NOTE: because of Perl numeric notation defaults,
the _num'ified obj may lose accuracy due to
machine-dependend floating point size limitations
_add(obj,obj) Simple addition of two objects
_mul(obj,obj) Multiplication of two objects
_div(obj,obj) Division of the 1st object by the 2nd
In list context, returns (result,reminder).
NOTE: this is integer math, so there will no
fractional part be returned.
_sub(obj,obj) Simple substraction of 1 object from another
a third, optional parameter indicates that the params
are swapped. In this case, the first param needs to
be preserved, while you can destroy the second.
sub (x,y,1) => return x - y and keep x intact!
_acmp(obj,obj) <=> operator for objects (return -1, 0 or 1)
_len(obj) returns count of the decimal digits of the object
_digit(obj,n) returns the n'th decimal digit of object
_is_one(obj) return true if argument is +1
_is_zero(obj) return true if argument is 0
_is_even(obj) return true if argument is even (0,2,4,6..)
_is_odd(obj) return true if argument is odd (1,3,5,7..)
_copy return a ref to a true copy of the object
_check(obj) check whether internal representation is still intact
return 0 for ok, otherwise error message as string
The following functions are optional, and can be exported if the underlying lib has a fast way to do them. If not defined, Math::BigInt will use a pure, but slow Perl function as fallback to emulate these:
_from_hex(str) return ref to new object from ref to hexadecimal string
_from_bin(str) return ref to new object from ref to binary string
_rsft(obj,N,B) shift object in base B by N 'digits' right
_lsft(obj,N,B) shift object in base B by N 'digits' left
_xor(obj1,obj2) XOR (bit-wise) object 1 with object 2
Mote: XOR, AND and OR pad with zeros if size mismatches
_and(obj1,obj2) AND (bit-wise) object 1 with object 2
_or(obj1,obj2) OR (bit-wise) object 1 with object 2
_sqrt(obj) return the square root of object
_pow(obj,obj) return object 1 to the power of object 2
_gcd(obj,obj) return Greatest Common Divisor of two objects
_zeros(obj) return amount of trailing decimal zeros
_dec(obj) decrement object by one (input is >= 1)
_inc(obj) increment object by one
Input strings come in as unsigned but with prefix (aka as '123', '0xabc' or '0b1101').
Testing of input parameter validity is done by the caller, so you need not to worry about underflow (_sub()
, _dec()
) nor division by zero or similiar cases.
LICENSE
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
AUTHORS
Original math code by Mark Biggar, rewritten by Tels http://bloodgate.com/ in late 2000, 2001. Seperated from BigInt and shaped API with the help of John Peacock.