Literals & quoting

FatRat — unlimited-precision rationals

Full

A rational whose numerator and denominator grow without bound.

A FatRat is like a Rat but with no limit on the size of its denominator. Where a Rat degrades to floating point once its denominator outgrows a machine word, a FatRat stays exact however large the parts become.

Exact past the Rat limit #

say (10 ** 20).FatRat / 3 + 1;
say (1/3).FatRat.WHAT;
Output
33333333333333333334.333333
(FatRat)

The value is held exactly as a big numerator over 3; say still rounds the display to six places, but the stored value is precise.

Exactly reversible #

Because nothing is lost to floating point, operations undo cleanly — a third times three is exactly one, not 0.9999….

my $f = (1/3).FatRat;
say $f * 3;
say $f * 3 == 1;
Output
1
True

Notes #