bigrat

Implements big rational support for Perl. For example, if you want to add the fractions 1/2 + 3/8, you can use bigrat to calculate the result and display it in fractional form: 7/8. Or in Perl terms:

#!/usr/local/bin/perl -w
use bigrat;
 
my $frac1 = 1/2;
my $frac2 = 3/8;
print $frac1 + $frac2, "\n"; # Prints 7/8

As of Perl 5.8, bigrat is shipped with the Perl source kit.

Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.