Math::BigInt, Math::BigFloat - Calculation of numbers with large digits
Perl's number has about 15 to 16 significant digits, and ordinary operations cannot perform larger numbers. Use Math::BigInt or Math::BigFloat if you want to work with large digits.
Large integer arithmetic
To calculate a large integer, use the object created by the Math::BigInt module.
use Math::BigInt; my $big_int = Math::BigInt->new("11111111111111111111111111111111111111111111"); $big_int = $big_int * 2;
Calculation of numbers with a large number of digits after the decimal point
Calculation is performed using the object created by the Math::BigFloat module.
use Math::BigFloat; my $big_float = Math::BigFloat->new("0.1111111111111111111111111111111111111"); $big_float = $big_float * 2;
Example
This is an example using Math::BigInt and Math::BigFloat.
use strict; use warnings; use Math::BigInt; use Math::BigFloat; print "(1) Operation of large integers\n"; my $big_int = Math::BigInt->new("11111111111111111111111111111111111111111111"); $big_int = $big_int * 2; print $big_int. "\n\n"; print "(2) Operations on numbers with a large number of digits after the decimal point\n"; my $big_float = Math::BigFloat->new("0.1111111111111111111111111111111111111"); $big_float = $big_float * 2; print $big_float . "\n";