Created
May 8, 2012 22:08
-
-
Save TimToady/2639796 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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