/****************************************************************************** * This program demonstrates the math library. * * Copyright © 2016 Richard Lesh. All rights reserved. *****************************************************************************/ #include #include #include #include #include using namespace std; int main(int argc, char **argv) { double const a = M_PI / 6; double const b = M_PI / 4; double const c = -a * 2; double const d = -b * 2; double const e = M_E; cout << fmt::format("pi = {0:f}", M_PI) << endl; cout << fmt::format("e = {0:f}", M_E) << endl; // abs, floor, ceil, round, trunc, min, max cout << fmt::format("abs({0:f}) = {1:f}", a, abs(a)) << endl; cout << fmt::format("abs({0:f}) = {1:f}", c, abs(c)) << endl; cout << fmt::format("floor({0:f}) = {1:f}", a, floor(a)) << endl; cout << fmt::format("floor({0:f}) = {1:f}", c, floor(c)) << endl; cout << fmt::format("ceil({0:f}) = {1:f}", a, ceil(a)) << endl; cout << fmt::format("ceil({0:f}) = {1:f}", c, ceil(c)) << endl; cout << fmt::format("round({0:f}) = {1:f}", a, floor(a + 0.5)) << endl; cout << fmt::format("round({0:f}) = {1:f}", c, floor(c + 0.5)) << endl; cout << fmt::format("trunc({0:f}) = {1:f}", a, trunc(a)) << endl; cout << fmt::format("trunc({0:f}) = {1:f}", c, trunc(c)) << endl; cout << fmt::format("min({0:f}, {1:f}) = {2:f}", a, c, min(a, c)) << endl; cout << fmt::format("max({0:f}, {1:f}) = {2:f}", a, c, max(a, c)) << endl; // sin, cos, tan, atan, atan2, acos, asin cout << fmt::format("sin({0:f}) = {1:f}", a, sin(a)) << endl; cout << fmt::format("sin({0:f}) = {1:f}", b, sin(b)) << endl; cout << fmt::format("sin({0:f}) = {1:f}", c, sin(c)) << endl; cout << fmt::format("sin({0:f}) = {1:f}", d, sin(d)) << endl; cout << fmt::format("cos({0:f}) = {1:f}", a, cos(a)) << endl; cout << fmt::format("cos({0:f}) = {1:f}", b, cos(b)) << endl; cout << fmt::format("cos({0:f}) = {1:f}", c, cos(c)) << endl; cout << fmt::format("cos({0:f}) = {1:f}", d, cos(d)) << endl; cout << fmt::format("tan({0:f}) = {1:f}", a, tan(a)) << endl; cout << fmt::format("tan({0:f}) = {1:f}", b, tan(b)) << endl; cout << fmt::format("tan({0:f}) = {1:f}", c, tan(c)) << endl; cout << fmt::format("asin({0:f}) = {1:f}", sin(a), asin(sin(a))) << endl; cout << fmt::format("asin({0:f}) = {1:f}", sin(b), asin(sin(b))) << endl; cout << fmt::format("asin({0:f}) = {1:f}", sin(c), asin(sin(c))) << endl; cout << fmt::format("asin({0:f}) = {1:f}", sin(d), asin(sin(d))) << endl; cout << fmt::format("acos({0:f}) = {1:f}", cos(a), acos(cos(a))) << endl; cout << fmt::format("acos({0:f}) = {1:f}", cos(b), acos(cos(b))) << endl; cout << fmt::format("acos({0:f}) = {1:f}", cos(c), acos(cos(c))) << endl; cout << fmt::format("acos({0:f}) = {1:f}", cos(d), acos(cos(d))) << endl; cout << fmt::format("atan({0:f}) = {1:f}", tan(a), atan(tan(a))) << endl; cout << fmt::format("atan({0:f}) = {1:f}", tan(b), atan(tan(b))) << endl; cout << fmt::format("atan({0:f}) = {1:f}", tan(c), atan(tan(c))) << endl; // 45 degrees cout << fmt::format("atan2({0:f}, {1:f}) = {2:f}", 1.0, 1.0, atan2(1.0, 1.0)) << endl; // 30 degrees cout << fmt::format("atan2({0:f}, {1:f}) = {2:f}", 1.0, sqrt(3.0), atan2(1.0, sqrt(3.0))) << endl; // sinh, cosh, tanh, atanh, acosh, asinh cout << fmt::format("sinh({0:f}) = {1:f}", a, sinh(a)) << endl; cout << fmt::format("sinh({0:f}) = {1:f}", b, sinh(b)) << endl; cout << fmt::format("sinh({0:f}) = {1:f}", c, sinh(c)) << endl; cout << fmt::format("sinh({0:f}) = {1:f}", d, sinh(d)) << endl; cout << fmt::format("cosh({0:f}) = {1:f}", a, cosh(a)) << endl; cout << fmt::format("cosh({0:f}) = {1:f}", b, cosh(b)) << endl; cout << fmt::format("cosh({0:f}) = {1:f}", c, cosh(c)) << endl; cout << fmt::format("cosh({0:f}) = {1:f}", d, cosh(d)) << endl; cout << fmt::format("tanh({0:f}) = {1:f}", a, tanh(a)) << endl; cout << fmt::format("tanh({0:f}) = {1:f}", b, tanh(b)) << endl; cout << fmt::format("tanh({0:f}) = {1:f}", c, tanh(c)) << endl; cout << fmt::format("tanh({0:f}) = {1:f}", d, tanh(d)) << endl; cout << fmt::format("asinh({0:f}) = {1:f}", sinh(a), asinh(sinh(a))) << endl; cout << fmt::format("asinh({0:f}) = {1:f}", sinh(b), asinh(sinh(b))) << endl; cout << fmt::format("asinh({0:f}) = {1:f}", sinh(c), asinh(sinh(c))) << endl; cout << fmt::format("asinh({0:f}) = {1:f}", sinh(d), asinh(sinh(d))) << endl; cout << fmt::format("acosh({0:f}) = {1:f}", cosh(a), acosh(cosh(a))) << endl; cout << fmt::format("acosh({0:f}) = {1:f}", cosh(b), acosh(cosh(b))) << endl; cout << fmt::format("acosh({0:f}) = {1:f}", cosh(c), acosh(cosh(c))) << endl; cout << fmt::format("acosh({0:f}) = {1:f}", cosh(d), acosh(cosh(d))) << endl; cout << fmt::format("atanh({0:f}) = {1:f}", tanh(a), atanh(tanh(a))) << endl; cout << fmt::format("atanh({0:f}) = {1:f}", tanh(b), atanh(tanh(b))) << endl; cout << fmt::format("atanh({0:f}) = {1:f}", tanh(c), atanh(tanh(c))) << endl; cout << fmt::format("atanh({0:f}) = {1:f}", tanh(d), atanh(tanh(d))) << endl; // log, log10, exp, pow, sqrt cout << fmt::format("log({0:f}) = {1:f}", a, log(a)) << endl; cout << fmt::format("log({0:f}) = {1:f}", b, log(b)) << endl; cout << fmt::format("log({0:f}) = {1:f}", -c, log(-c)) << endl; cout << fmt::format("log({0:f}) = {1:f}", -d, log(-d)) << endl; cout << fmt::format("log({0:f}) = {1:f}", e, log(e)) << endl; cout << fmt::format("log10({0:f}) = {1:f}", a, log10(a)) << endl; cout << fmt::format("log10({0:f}) = {1:f}", b, log10(b)) << endl; cout << fmt::format("log10({0:f}) = {1:f}", -c, log10(-c)) << endl; cout << fmt::format("log10({0:f}) = {1:f}", -d, log10(-d)) << endl; cout << fmt::format("log10({0:f}) = {1:f}", e, log10(e)) << endl; cout << fmt::format("exp({0:f}) = {1:f}", 0.5, exp(0.5)) << endl; cout << fmt::format("exp({0:f}) = {1:f}", 1.0, exp(1.0)) << endl; cout << fmt::format("exp({0:f}) = {1:f}", 2.0, exp(2.0)) << endl; cout << fmt::format("pow({0:f}, {1:f}) = {2:f}", 10.0, 0.5, pow(10.0, 0.5)) << endl; cout << fmt::format("pow({0:f}, {1:f}) = {2:f}", 10.0, 1.0, pow(10.0, 1.0)) << endl; cout << fmt::format("pow({0:f}, {1:f}) = {2:f}", 10.0, 2.0, pow(10.0, 2.0)) << endl; cout << fmt::format("sqrt({0:f}) = {1:f}", 0.5, sqrt(0.5)) << endl; cout << fmt::format("sqrt({0:f}) = {1:f}", 2.0, sqrt(2.0)) << endl; cout << fmt::format("sqrt({0:f}) = {1:f}", 10.0, sqrt(10.0)) << endl; // random numbers cout << fmt::format("random() = {0:f}", rand()/(RAND_MAX + 1.0)) << endl; cout << fmt::format("random() = {0:f}", rand()/(RAND_MAX + 1.0)) << endl; cout << fmt::format("random() = {0:f}", rand()/(RAND_MAX + 1.0)) << endl; return 0; }