50 if ((p.x * p.x) + (p.y * p.y) <= 1) {
54 return 4.0 * count /
static_cast<double>(pts.size());
63 std::vector<math::Point> rands;
64 for (std::size_t i = 0; i < 100000; i++) {
66 p.x = rand() /
static_cast<double>(RAND_MAX);
67 p.y = rand() /
static_cast<double>(RAND_MAX);
73 std::cout <<
"All tests have successfully passed!" << std::endl;
static void tests()
Self-test implementations.
struct { double x; double y;} Point
structure of points containing two numbers, x and y, such that 0 ≤ x ≤ 1 and 0 ≤ y ≤ 1.
double approximate_pi(const std::vector< Point > &pts)
This function uses the points in a given vector 'pts' (drawn at random) to return an approximation of...