// // boost_multiprecision_power_demo.cpp // // Created by Jan Bouwer on 8/7/13. #include #include #include #include #include const double errorMargin = 0.00001; template void test_power_int(double b, int e) { const T xb(b), xe(e); using namespace std; cout << "pow(" << b << ", " << e << ") = " << pow(xb, e) << (double(pow(xb, e)) - pow(b, e) < errorMargin ? "" : " - Unexpected!") << endl; } template void test_power_float(double b, double e) { const T xb(b), xe(e); pow(xb, xe); using namespace std; cout << "pow(" << b << ", " << e << ") = " << pow(xb, xe) << (double(pow(xb, xe)) - pow(b, e) < errorMargin ? "" : " - Unexpected!") << endl; } void test_boost_mp() { using namespace boost::multiprecision; using T = cpp_dec_float_50; assert( pow(T(0), T(2)) == 0 ); // Failure test_power_int(0, 0); test_power_int(0, 1); test_power_int(0, 2); test_power_int(1, 0); test_power_int(1, 1); test_power_int(1, 2); test_power_int(2, 0); test_power_int(2, 1); test_power_int(2, 2); test_power_float(0, 0); test_power_float(0, 1); test_power_float(0, 2); test_power_float(1, 0); test_power_float(1, 1); test_power_float(1, 2); test_power_float(2, 0); test_power_float(2, 1); test_power_float(2, 2); test_power_float(0, 0); test_power_float(0, 1); test_power_float(0, 2); test_power_float(1, 0); test_power_float(1, 1); test_power_float(1, 2); test_power_float(2, 0); test_power_float(2, 1); test_power_float(2, 2); test_power_float>>(0, 0); test_power_float>>(0, 1); test_power_float>>(0, 2); test_power_float>>(1, 0); test_power_float>>(1, 1); test_power_float>>(1, 2); test_power_float>>(2, 0); test_power_float>>(2, 1); test_power_float>>(2, 2); }