https://github.com/sysprog21/compute-pi
Leibniz formula for π
https://github.com/sysprog21/compute-pi
Last synced: 8 months ago
JSON representation
Leibniz formula for π
- Host: GitHub
- URL: https://github.com/sysprog21/compute-pi
- Owner: sysprog21
- License: other
- Created: 2016-09-23T17:14:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-10-02T18:30:56.000Z (about 6 years ago)
- Last Synced: 2025-05-08T23:54:04.057Z (8 months ago)
- Language: C
- Size: 19.5 KB
- Stars: 11
- Watchers: 4
- Forks: 106
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 採用離散積分的方法求圓周率,並著手透過 SIMD 指令作效能最佳化
Authored by Lee Chao Yuan ``

## 相關連結
* [開發紀錄與效能分析](https://charles620016.hackpad.com/Charles-Week-1-kBMD0GhbC7d)
* [Leibniz formula for π](https://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80)
## Baseline 版本
```c
double computePi_v1(size_t N)
{
double pi = 0.0;
double dt = 1.0 / N; // dt = (b-a)/N, b = 1, a = 0
for (size_t i = 0; i < N; i++) {
double x = (double) i / N; // x = ti = a+(b-a)*i/N = i/N
pi += dt / (1.0 + x * x); // integrate 1/(1+x^2), i = 0....N
}
return pi * 4.0;
}
```
## Benchmarking


