MCPcopy Create free account
hub / github.com/Compaile/ctrack / estimate_pi

Function estimate_pi

examples/high_variance_pi_estimation.cpp:7–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include "ctrack.hpp"
6
7double estimate_pi(int points) {
8 CTRACK;
9 std::random_device rd;
10 std::mt19937 gen(rd());
11 std::uniform_real_distribution<> dis(-1.0, 1.0);
12
13 int inside_circle = 0;
14 for (int i = 0; i < points; ++i) {
15 double x = dis(gen);
16 double y = dis(gen);
17 if (x*x + y*y <= 1.0) {
18 inside_circle++;
19 }
20 }
21
22 return 4.0 * inside_circle / points;
23}
24
25void run_estimations(int iterations, int points_per_estimation) {
26 for (int i = 0; i < iterations; ++i) {

Callers 1

run_estimationsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected