Perl Language Reference Manualby Larry Wall and others Paperback (6"x9"), 724 pages ISBN 9781906966027 RRP £29.95 ($39.95) Sales of this book support The Perl Foundation! Get a printed copy>>> |

## 7.39 Bigger Numbers

The standard Math::BigInt and Math::BigFloat modules provide variable-precision arithmetic and overloaded operators, although they're currently pretty slow. At the cost of some space and considerable speed, they avoid the normal pitfalls associated with limited-precision representations.

use Math::BigInt; $x = Math::BigInt->new('123456789123456789'); print $x * $x; # prints +15241578780673678515622620750190521

There are several modules that let you calculate with (bound only by memory and cpu-time) unlimited or fixed precision. There are also some non-standard modules that provide faster implementations via external C libraries.

Here is a short, but incomplete summary:

Math::Fraction big, unlimited fractions like 9973 / 12967 Math::String treat string sequences like numbers Math::FixedPrecision calculate with a fixed precision Math::Currency for currency calculations Bit::Vector manipulate bit vectors fast (uses C) Math::BigIntFast Bit::Vector wrapper for big numbers Math::Pari provides access to the Pari C library Math::BigInteger uses an external C library Math::Cephes uses external Cephes C library (no big numbers) Math::Cephes::Fraction fractions via the Cephes library Math::GMP another one using an external C library

Choose wisely.

ISBN 9781906966027 | Perl Language Reference Manual | See the print edition |