chundoong-lab-ta/APWS23/integral-skeleton/integral_cpu.cpp

12 lines
277 B
C++
Raw Normal View History

2023-02-09 01:28:51 +09:00
#include "integral.h"
2023-02-14 01:23:28 +09:00
static double f(double x) { return 4.0 / (1 + x * x); }
2023-02-09 01:28:51 +09:00
double integral_cpu(size_t num_intervals) {
double dx = (1.0 / (double) num_intervals);
double sum = 0;
2023-02-14 01:23:28 +09:00
for (size_t i = 0; i < num_intervals; i++) { sum += f(i * dx) * dx; }
2023-02-09 01:28:51 +09:00
return sum;
}