MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / piSugar

Function piSugar

inst/examples/Misc/piSugar.cpp:7–12  ·  view source on GitHub ↗

[[Rcpp::export]]

Source from the content-addressed store, hash-verified

5
6// [[Rcpp::export]]
7double piSugar(const int N) {
8 NumericVector x = runif(N);
9 NumericVector y = runif(N);
10 NumericVector d = sqrt(x*x + y*y);
11 return 4.0 * sum(d < 1.0) / N;
12}

Callers

nothing calls this directly

Calls 3

runifFunction · 0.50
sqrtFunction · 0.50
sumFunction · 0.50

Tested by

no test coverage detected