#include #include //for the i/o manipulator setprecision #include #include //for std::numbers::pi Compile with -std=c++20 using namespace std; /* Get closer and closer to the value of pi by adding up 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + ... */ template T f() { T pi {0}; T sign {1}; for (T i {1}; i < 32500000; i += 2) { pi += sign/i; sign = -sign; } return 4 * pi; } int main() { cout << fixed << setprecision(8); //digits to right of decimal point cout << "pi = " << numbers::pi << "\n"; cout << "float: " << f() << "\n"; cout << "double: " << f() << "\n"; return EXIT_SUCCESS; }