You are viewing the version of this documentation from Perl 5.26.1. View the latest version

CONTENTS

NAME

Math::BigInt::Lib - virtual parent class for Math::BigInt libraries

SYNOPSIS

This 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.

DESCRIPTION

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'.

General Notes

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.

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.

API version

api_version()

Return API version 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.

Constructors

The following methods are mandatory: _new(), _str(), _add(), and _sub(). However, computations will be very slow without _mul() and _div().

_new(STR)

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*)$.

_zero()

Return an object representing the number zero.

_one()

Return an object representing the number one.

_two()

Return an object representing the number two.

_ten()

Return an object representing the number ten.

_from_bin(STR)

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]*)$.

_from_oct(STR)

Return an object given a string representing an octal number. The input has a '0' prefix and matches the regular expression ^0[1-7]*$.

_from_hex(STR)

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]*)$.

_from_bytes(STR)

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.