Skip to content

Instantly share code, notes, and snippets.

@treyharris
Created July 26, 2021 17:54
Show Gist options
  • Save treyharris/4b3be9223245395d21bfdc62579d0331 to your computer and use it in GitHub Desktop.
Save treyharris/4b3be9223245395d21bfdc62579d0331 to your computer and use it in GitHub Desktop.
Playing with Raku Rat and sqrt
rat's type is Rat
z's type is Rat
13 6 squared= 169 36
Rat(169 36)'s sqrt, 2.1666666666666665, is a Num, but coerced, is Rat(13 6)
my $x = 13;
my $y = 6;
my $rat = Rat($x/$y);
my $z = $rat**2;
say "rat's type is ", $rat.^name;
say "z's type is ", $z.^name;
say "{$rat.nude} squared= {$z.nude}";
my $root = sqrt($z);
say "Rat({$z.nude})'s sqrt, $root, is a {$root.^name}, but coerced, is Rat({Rat($root).nude})";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment