Rcpp Version 1.0.14
Loading...
Searching...
No Matches
piSugar.cpp
Go to the documentation of this file.
1
2
#include <
Rcpp.h
>
3
4
using namespace
Rcpp
;
5
6
// [[Rcpp::export]]
7
double
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
}
Rcpp.h
Rcpp::Vector
Definition
Vector.h:35
Rcpp
Rcpp API.
Definition
algo.h:28
Rcpp::runif
NumericVector runif(int n, double min, double max)
Definition
random.h:295
Rcpp::as
T as(SEXP x)
Definition
as.h:151
Rcpp::sum
sugar::Sum< INTSXP, NA, T > sum(const VectorBase< INTSXP, NA, T > &t)
Definition
sum.h:98
piSugar
double piSugar(const int N)
Definition
piSugar.cpp:7
inst
examples
Misc
piSugar.cpp
Generated on Sun Jan 12 2025 11:21:42 for Rcpp Version 1.0.14 by
1.9.8