Skip to content

Instantly share code, notes, and snippets.

@dwarring
Last active December 24, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwarring/6847212 to your computer and use it in GitHub Desktop.
Save dwarring/6847212 to your computer and use it in GitHub Desktop.
nqp / rakudo taylor approx
# naive approximation: pi = 1 - /1/3 + 1/5 ...
# language: perl6 / nqp
my $limit := 20_000;
my $n := 1;
my $pi_over_4 := 0.0;
while $n < $limit {
## my $m := 4.0*$n - 1.0; # this was making $m a Rat
my $m := (4*$n - 1).Num;
$pi_over_4 := $pi_over_4 + 1/($m - 2) - 1/$m;
$n := $n + 1;
}
my $pi := $pi_over_4 * 4;
say($pi);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment