/****************************************************************************** * Various trigonometric approximations to Pi. * * Copyright © 2017 Richard Lesh. All rights reserved. *****************************************************************************/ #include #include #include #include #include #include #include std::locale utf8loc(std::locale(), new std::codecvt_utf8); using namespace std; int main(int argc, char **argv) { setlocale(LC_ALL, "en_US.UTF-8"); wcout.imbue(utf8loc); wcin.imbue(utf8loc); double const pi1 = atan(1.0) * 4.0; double const pi2 = atan2(0.0, -1.0); double const pi3 = acos(-1.0); double const pi4 = 2.0 * acos(0.0); wcout << fmt::format(L"pi1: {0:.15f}", pi1) << endl; wcout << fmt::format(L"abs(pi1 - π): {0:.10e}", abs(pi1 - M_PI)) << endl; wcout << fmt::format(L"pi2: {0:.15f}", pi2) << endl; wcout << fmt::format(L"abs(pi2 - π): {0:.10e}", abs(pi2 - M_PI)) << endl; wcout << fmt::format(L"pi3: {0:.15f}", pi3) << endl; wcout << fmt::format(L"abs(pi3 - π): {0:.10e}", abs(pi3 - M_PI)) << endl; wcout << fmt::format(L"pi4: {0:.15f}", pi4) << endl; wcout << fmt::format(L"abs(pi4 - π): {0:.10e}", abs(pi4 - M_PI)) << endl; return 0; }