Perl6 Pi and continued fractions
I was looking through the code of the Rakudo implementation of Perl6 where I noticed that it defines pi as my constant pi = 3.14159_26535_89793_238e0;
( with an alias my constant π := pi;
)
I immediately remembered that for a subset of fractional numbers Perl6 has a type that stores them without the loss of precision that generally accompanies floating point math. That type is of course the Rat (and FatRat) type. So of course I type pi.Rat
into the REPL, it then prints 3.141593
which is obviously nowhere near as precise as the result of just typing pi
into the REPL 3.14159265358979
.
I wanted to see the numerator and denominator values that Perl chose to use so I typed pi.Rat.perl
and got <355/113>
, which is nowhere near as precise as the Rat type is capable of handling. That was just the entrance to the rabbit hole.