/****************************************************************************** * This program prints physical constants. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #undef NDEBUG #include #include #include #include #include #include #include std::locale utf8loc(std::locale(), new std::codecvt_utf8); using namespace std; static double const AVOGADRO = 6.0221412927e23; static double const ELECTRON_MASS = 9.1093821545e-31; int main(int argc, char **argv) { setlocale(LC_ALL, "en_US.UTF-8"); wcout.imbue(utf8loc); wcin.imbue(utf8loc); wcout << L"General Format" << endl; wcout << fmt::format(L"π: {0:g} {0:.2g} |{0:10.2g}|", M_PI) << endl; wcout << fmt::format(L"ℯ: {0:g} {0:.2g} |{0:10.2g}|", M_E) << endl; wcout << fmt::format(L"N\u2090: {0:g} {0:.2g} |{0:10.2g}|", AVOGADRO) << endl; wcout << fmt::format(L"m\u2091: {0:g} {0:.2g} |{0:10.2g}|", ELECTRON_MASS) << endl; wcout << L"Fixed Format" << endl; wcout << fmt::format(L"π: {0:f} {0:.2f} |{0:10.2f}|", M_PI) << endl; wcout << fmt::format(L"ℯ: {0:f} {0:.2f} |{0:10.2f}|", M_E) << endl; wcout << fmt::format(L"N\u2090: {0:f} {0:.2f} |{0:10.2f}|", AVOGADRO) << endl; wcout << fmt::format(L"m\u2091: {0:f} {0:.2f} |{0:10.2f}|", ELECTRON_MASS) << endl; wcout << L"Scientific Format" << endl; wcout << fmt::format(L"π: {0:e} {0:.2e} |{0:10.2e}|", M_PI) << endl; wcout << fmt::format(L"ℯ: {0:e} {0:.2e} |{0:10.2e}|", M_E) << endl; wcout << fmt::format(L"N\u2090: {0:e} {0:.2e} |{0:10.2e}|", AVOGADRO) << endl; wcout << fmt::format(L"m\u2091: {0:e} {0:.2e} |{0:10.2e}|", ELECTRON_MASS) << endl; return 0; }