Skip to content

Instantly share code, notes, and snippets.

@TimToady
Created May 8, 2012 22:08
Show Gist options
  • Save TimToady/2639796 to your computer and use it in GitHub Desktop.
Save TimToady/2639796 to your computer and use it in GitHub Desktop.
sub r2s (Rat $rat) {
my $s = $rat < 0 ?? '-' !! '';
my $r = $rat.abs;
my $i = $r.floor;
$r -= $i;
$s ~= $i;
if $r {
$s ~= '.';
while $r and $s.chars < 41 {
$r *= 10;
$i = $r.floor;
$s ~= $i;
$r -= $i;
}
}
$s;
}
say r2s(241025348275725.3352);
say r2s(2**64 / 1 + 1/3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment