Sign

The sign is either '+', '-', 'NaN', '+inf' or '-inf'.

A sign of 'NaN' is used to represent the result when input arguments are not
numbers or as a result of 0/0. '+inf' and '-inf' represent plus respectively
minus infinity. You will get '+inf' when dividing a positive number by 0, and
'-inf' when dividing any negative number by 0.

Methods

Since all numbers are not objects, you can use all functions that are part of
the BigInt or BigFloat API. It is wise to use only the bxxx() notation, and not
the fxxx() notation, though. This makes you independent on the fact that the
underlying object might morph into a different class than BigFloat.

inf()

A shortcut to return Math::BigInt->binf(). Useful because Perl does not always
handle bareword inf
properly.

NaN()

A shortcut to return Math::BigInt->bnan(). Useful because Perl does not always
handle bareword NaN
properly.

e

# perl -Mbigrat=e -wle 'print e'

Returns Euler's number e
, aka exp(1).

PI

# perl -Mbigrat=PI -wle 'print PI'

Returns PI.

bexp()

bexp($power,$accuracy);

Returns Euler's number e
raised to the appropriate power, to
the wanted accuracy.

Example:

# perl -Mbigrat=bexp -wle 'print bexp(1,80)'

bpi()

bpi($accuracy);

Returns PI to the wanted accuracy.

Example:

# perl -Mbigrat=bpi -wle 'print bpi(80)'

upgrade()

Return the class that numbers are upgraded to, is in fact returning
$Math::BigInt::upgrade
.

See the documentation about the copy constructor and =
in overload, as
well as the documentation in BigInt for further details.

Options

bignum recognizes some options that can be passed while loading it via use.
The options can (currently) be either a single letter form, or the long form.
The following options exist:

a or accuracy

This sets the accuracy for all math operations. The argument must be greater
than or equal to zero. See Math::BigInt's bround() function for details.

perl -Mbigrat=a,50 -le 'print sqrt(20)'

Note that setting precision and accuracy at the same time is not possible.

p or precision

This sets the precision for all math operations. The argument can be any
integer. Negative values mean a fixed number of digits after the dot, while
a positive value rounds to this digit left from the dot. 0 or 1 mean round to
integer. See Math::BigInt's bfround() function for details.

perl -Mbigrat=p,-50 -le 'print sqrt(20)'

Note that setting precision and accuracy at the same time is not possible.

t or trace

This enables a trace mode and is primarily for debugging bignum or
Math::BigInt/Math::BigFloat.

Currently there is no way to specify more than one library on the command
line. This means the following does not work:

perl -Mbignum=l,GMP,Pari -e 'print 2 ** 512'

This will be hopefully fixed soon ;)

hex

Override the built-in hex() method with a version that can handle big
numbers. This overrides it by exporting it to the current package. Under
Perl v5.10.0 and higher, this is not so necessary, as hex() is lexically
overridden in the current scope whenever the bigrat pragma is active.

oct

Override the built-in oct() method with a version that can handle big
numbers. This overrides it by exporting it to the current package. Under
Perl v5.10.0 and higher, this is not so necessary, as oct() is lexically
overridden in the current scope whenever the bigrat pragma is active.

v or version

This prints out the name and version of all modules used and then exits.

perl -Mbigrat=v

CAVEATS

in_effect()

This method only works on Perl v5.9.4 or later.

hex()/oct()

bigint
overrides these routines with versions that can also handle
big integer values. Under Perl prior to version v5.9.4, however, this
will not happen unless you specifically ask for it with the two
import tags "hex" and "oct" - and then it will be global and cannot be
disabled inside a scope with "no bigint":