Literals & quoting
FatRat — unlimited-precision rationals
FullA 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
TrueNotes #
- Coerce into the type with
.FatRat; arithmetic that mixes aFatRatwith other numbers promotes the result toFatRat, keeping it exact. - Use it when you need exact rationals with very large or repeatedly-multiplied denominators (continued fractions, high-precision series); a plain
Ratis fine for everyday decimals. - The numeric tower is
Int⊂Rat⊂FatRat⊂Num;FatRatsits aboveRatprecisely because it removes the denominator-size ceiling.