Rational numbers in Perl


If you want to deal with rational numbers, Perl has you covered.

Remember previous post Be Rational? If you’re convinced that rational numbers are the right way to go for some problem, please remember that Perl has Math::BigRat at your disposal:

use Math::BigRat;
my $x = Math::BigRat->new('3/7'); $x += '5/9';
print $x->bstr(), "\n";
print $x ** 2, "\n";
my $y = Math::BigRat->new('inf');
print "$y ", ($y->is_inf ? 'is' : 'is not'), " infinity\n";

So no… it was not a module for a big rat 🐀

Comments? Octodon, , GitHub, Reddit, or drop me a line!