mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
Remove uses of boost/cstdint without header called
This commit is contained in:
@@ -82,13 +82,13 @@ int main()
|
||||
// the abscissa value that yields 3, not zero. We pass the functor b by value to the
|
||||
// lambda expression since barycentric_rational is trivial to copy.
|
||||
// Here we're using simple bisection to find the root:
|
||||
boost::uintmax_t iterations = (std::numeric_limits<boost::uintmax_t>::max)();
|
||||
std::uintmax_t iterations = (std::numeric_limits<std::uintmax_t>::max)();
|
||||
double abscissa_3 = boost::math::tools::bisect([=](double x) { return b(x) - 3; }, 0.44, 1.24, boost::math::tools::eps_tolerance<double>(), iterations).first;
|
||||
std::cout << "Abscissa value that yields a potential of 3 = " << abscissa_3 << std::endl;
|
||||
std::cout << "Root was found in " << iterations << " iterations." << std::endl;
|
||||
//
|
||||
// However, we have a more efficient root finding algorithm than simple bisection:
|
||||
iterations = (std::numeric_limits<boost::uintmax_t>::max)();
|
||||
iterations = (std::numeric_limits<std::uintmax_t>::max)();
|
||||
abscissa_3 = boost::math::tools::bracket_and_solve_root([=](double x) { return b(x) - 3; }, 0.6, 1.2, false, boost::math::tools::eps_tolerance<double>(), iterations).first;
|
||||
std::cout << "Abscissa value that yields a potential of 3 = " << abscissa_3 << std::endl;
|
||||
std::cout << "Root was found in " << iterations << " iterations." << std::endl;
|
||||
|
||||
@@ -57,10 +57,10 @@ void no_et()
|
||||
|
||||
std::cout.setf(std::ios_base::boolalpha);
|
||||
|
||||
typedef number<backends::cpp_bin_float<113, backends::digit_base_2, void, boost::int16_t, -16382, 16383>, et_on> cpp_bin_float_quad_et_on;
|
||||
typedef number<backends::cpp_bin_float<113, backends::digit_base_2, void, boost::int16_t, -16382, 16383>, et_off> cpp_bin_float_quad_et_off;
|
||||
typedef number<backends::cpp_bin_float<113, backends::digit_base_2, void, std::int16_t, -16382, 16383>, et_on> cpp_bin_float_quad_et_on;
|
||||
typedef number<backends::cpp_bin_float<113, backends::digit_base_2, void, std::int16_t, -16382, 16383>, et_off> cpp_bin_float_quad_et_off;
|
||||
|
||||
typedef number<backends::cpp_bin_float<113, backends::digit_base_2, void, boost::int16_t, -16382, 16383>, et_off> cpp_bin_float_oct;
|
||||
typedef number<backends::cpp_bin_float<113, backends::digit_base_2, void, std::int16_t, -16382, 16383>, et_off> cpp_bin_float_oct;
|
||||
|
||||
|
||||
cpp_bin_float_quad x("42.");
|
||||
|
||||
@@ -141,8 +141,8 @@ void show_minima()
|
||||
<< "\n Displaying to std::numeric_limits<T>::digits10 " << prec << ", significant decimal digits."
|
||||
<< std::endl;
|
||||
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
// Construct using string, not double, avoids loss of precision.
|
||||
//T bracket_min = static_cast<T>("-4");
|
||||
//T bracket_max = static_cast<T>("1.3333333333333333333333333333333333333333333333333");
|
||||
@@ -237,8 +237,8 @@ int main()
|
||||
// Specific type double - limit maxit to 20 iterations.
|
||||
std::cout << "Precision bits = " << bits << std::endl;
|
||||
//[brent_minimise_double_2
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
std::pair<double, double> r = brent_find_minima(funcdouble(), -4., 4. / 3, bits, it);
|
||||
std::cout << "x at minimum = " << r.first << ", f(" << r.first << ") = " << r.second
|
||||
<< " after " << it << " iterations. " << std::endl;
|
||||
@@ -273,8 +273,8 @@ int main()
|
||||
<< " decimal digits from tolerance " << sqrt(epsilon_2)
|
||||
<< std::endl;
|
||||
std::streamsize precision_4 = std::cout.precision(prec); // Save.
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it_4 = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it_4 = maxit;
|
||||
std::pair<double, double> r = brent_find_minima(funcdouble(), -4., 4. / 3, bits_div_2, it_4);
|
||||
std::cout << "x at minimum = " << r.first << ", f(" << r.first << ") = " << r.second << std::endl;
|
||||
std::cout << it_4 << " iterations. " << std::endl;
|
||||
@@ -294,9 +294,9 @@ int main()
|
||||
<< " decimal digits from tolerance " << sqrt(epsilon_4)
|
||||
<< std::endl;
|
||||
std::streamsize precision_5 = std::cout.precision(prec); // Save & set.
|
||||
const boost::uintmax_t maxit = 20;
|
||||
const std::uintmax_t maxit = 20;
|
||||
|
||||
boost::uintmax_t it_5 = maxit;
|
||||
std::uintmax_t it_5 = maxit;
|
||||
std::pair<double, double> r = brent_find_minima(funcdouble(), -4., 4. / 3, bits_div_4, it_5);
|
||||
std::cout << "x at minimum = " << r.first << ", f(" << r.first << ") = " << r.second
|
||||
<< ", after " << it_5 << " iterations. " << std::endl;
|
||||
@@ -316,8 +316,8 @@ int main()
|
||||
long double bracket_min = -4.;
|
||||
long double bracket_max = 4. / 3;
|
||||
const int bits = std::numeric_limits<long double>::digits;
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
|
||||
std::pair<long double, long double> r = brent_find_minima(func(), bracket_min, bracket_max, bits, it);
|
||||
std::cout << "x at minimum = " << r.first << ", f(" << r.first << ") = " << r.second
|
||||
@@ -380,8 +380,8 @@ int main()
|
||||
cpp_bin_float_50 bracket_max = static_cast<cpp_bin_float_50>("1.3333333333333333333333333333333333333333333333333");
|
||||
|
||||
std::cout << "Bracketing " << bracket_min << " to " << bracket_max << std::endl;
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit; // Will be updated with actual iteration count.
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit; // Will be updated with actual iteration count.
|
||||
std::pair<cpp_bin_float_50, cpp_bin_float_50> r
|
||||
= brent_find_minima(func(), bracket_min, bracket_max, bits, it);
|
||||
|
||||
@@ -432,8 +432,8 @@ f(0.99999999999999999999999999998813903221565569205253) =
|
||||
cpp_bin_float_50_et_on bracket_max = static_cast<cpp_bin_float_50_et_on>("1.3333333333333333333333333333333333333333333333333");
|
||||
|
||||
std::cout << bracket_min << " " << bracket_max << std::endl;
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
std::pair<cpp_bin_float_50_et_on, cpp_bin_float_50_et_on> r = brent_find_minima(func(), bracket_min, bracket_max, bits, it);
|
||||
|
||||
std::cout << "x at minimum = " << r.first << ", f(" << r.first << ") = " << r.second << std::endl;
|
||||
@@ -455,8 +455,8 @@ f(0.99999999999999999999999999998813903221565569205253) =
|
||||
cpp_bin_float_50_et_off bracket_max = static_cast<cpp_bin_float_50_et_off>("1.3333333333333333333333333333333333333333333333333");
|
||||
|
||||
std::cout << bracket_min << " " << bracket_max << std::endl;
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
std::pair<cpp_bin_float_50_et_off, cpp_bin_float_50_et_off> r = brent_find_minima(func(), bracket_min, bracket_max, bits, it);
|
||||
|
||||
std::cout << "x at minimum = " << r.first << ", f(" << r.first << ") = " << r.second << std::endl;
|
||||
@@ -475,8 +475,8 @@ f(0.99999999999999999999999999998813903221565569205253) =
|
||||
cpp_dec_float_50 bracket_max = static_cast<cpp_dec_float_50>("1.3333333333333333333333333333333333333333333333333");
|
||||
|
||||
std::cout << bracket_min << " " << bracket_max << std::endl;
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
std::pair<cpp_dec_float_50, cpp_dec_float_50> r = brent_find_minima(func(), bracket_min, bracket_max, bits, it);
|
||||
|
||||
std::cout << "x at minimum = " << r.first << ", f(" << r.first << ") = " << r.second << std::endl;
|
||||
@@ -494,8 +494,8 @@ f(0.99999999999999999999999999998813903221565569205253) =
|
||||
cpp_dec_float_50_et_on bracket_min = static_cast<cpp_dec_float_50_et_on>("-4");
|
||||
cpp_dec_float_50_et_on bracket_max = static_cast<cpp_dec_float_50_et_on>("1.3333333333333333333333333333333333333333333333333");
|
||||
std::cout << bracket_min << " " << bracket_max << std::endl;
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
std::pair<cpp_dec_float_50_et_on, cpp_dec_float_50_et_on> r = brent_find_minima(func(), bracket_min, bracket_max, bits, it);
|
||||
|
||||
std::cout << "x at minimum = " << r.first << ", f(" << r.first << ") = " << r.second << std::endl;
|
||||
@@ -515,8 +515,8 @@ f(0.99999999999999999999999999998813903221565569205253) =
|
||||
cpp_dec_float_50_et_off bracket_max = static_cast<cpp_dec_float_50_et_off>("1.3333333333333333333333333333333333333333333333333");
|
||||
|
||||
std::cout << bracket_min << " " << bracket_max << std::endl;
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
std::pair<cpp_dec_float_50_et_off, cpp_dec_float_50_et_off> r = brent_find_minima(func(), bracket_min, bracket_max, bits, it);
|
||||
|
||||
std::cout << "x at minimum = " << r.first << ", f(" << r.first << ") = " << r.second << std::endl;
|
||||
|
||||
@@ -72,7 +72,7 @@ private:
|
||||
template <class T>
|
||||
inline std::complex<T> expint_as_fraction(unsigned n, std::complex<T> const& z)
|
||||
{
|
||||
boost::uintmax_t max_iter = 1000;
|
||||
std::uintmax_t max_iter = 1000;
|
||||
expint_fraction<std::complex<T> > f(n, z);
|
||||
std::complex<T> result = boost::math::tools::continued_fraction_b(
|
||||
f,
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <boost/math/special_functions/factorials.hpp>
|
||||
#include <boost/multiprecision/cpp_bin_float.hpp>
|
||||
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_bin_float<237, boost::multiprecision::backends::digit_base_2, std::allocator<char>, boost::int32_t, -262142, 262143>, boost::multiprecision::et_off> octuple_type;
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_bin_float<237, boost::multiprecision::backends::digit_base_2, std::allocator<char>, std::int32_t, -262142, 262143>, boost::multiprecision::et_off> octuple_type;
|
||||
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
typedef boost::multiprecision::float128 float128_t;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
void expected_results();
|
||||
|
||||
typedef std::pair<boost::regex, std::pair<boost::uintmax_t, boost::uintmax_t> > expected_data_type;
|
||||
typedef std::pair<boost::regex, std::pair<std::uintmax_t, std::uintmax_t> > expected_data_type;
|
||||
typedef std::list<expected_data_type> list_type;
|
||||
|
||||
inline list_type&
|
||||
@@ -42,8 +42,8 @@ inline void add_expected_result(
|
||||
const char* type_name,
|
||||
const char* test_name,
|
||||
const char* group_name,
|
||||
boost::uintmax_t max_peek_error,
|
||||
boost::uintmax_t max_mean_error)
|
||||
std::uintmax_t max_peek_error,
|
||||
std::uintmax_t max_mean_error)
|
||||
{
|
||||
std::string re("(?:");
|
||||
re += compiler;
|
||||
@@ -89,10 +89,10 @@ inline std::string build_test_name(const char* type_name, const char* test_name,
|
||||
return result;
|
||||
}
|
||||
|
||||
inline const std::pair<boost::uintmax_t, boost::uintmax_t>&
|
||||
inline const std::pair<std::uintmax_t, std::uintmax_t>&
|
||||
get_max_errors(const char* type_name, const char* test_name, const char* group_name)
|
||||
{
|
||||
static const std::pair<boost::uintmax_t, boost::uintmax_t> defaults(1, 1);
|
||||
static const std::pair<std::uintmax_t, std::uintmax_t> defaults(1, 1);
|
||||
std::string name = build_test_name(type_name, test_name, group_name);
|
||||
list_type& l = get_expected_data();
|
||||
list_type::const_iterator a(l.begin()), b(l.end());
|
||||
@@ -165,7 +165,7 @@ void handle_test_result(const boost::math::tools::test_result<T>& result,
|
||||
//
|
||||
// Now verify that the results are within our expected bounds:
|
||||
//
|
||||
std::pair<boost::uintmax_t, boost::uintmax_t> const& bounds = get_max_errors(type_name, test_name, group_name);
|
||||
std::pair<std::uintmax_t, std::uintmax_t> const& bounds = get_max_errors(type_name, test_name, group_name);
|
||||
if(bounds.first < max_error_found)
|
||||
{
|
||||
std::cerr << "Peak error greater than expected value of " << bounds.first << std::endl;
|
||||
|
||||
@@ -64,7 +64,7 @@ int main()
|
||||
}
|
||||
|
||||
//template <class F, class T, class Tol, class Policy>std::pair<T, T>
|
||||
// bracket_and_solve_root(F f, const T& guess, T factor, bool rising, Tol tol, boost::uintmax_t& max_iter, const Policy& pol)
|
||||
// bracket_and_solve_root(F f, const T& guess, T factor, bool rising, Tol tol, std::uintmax_t& max_iter, const Policy& pol)
|
||||
|
||||
|
||||
//double df = inverse_chi_squared_distribution<>::find_degrees_of_freedom(diff, alpha, beta, variance, 0);
|
||||
|
||||
@@ -134,9 +134,9 @@ struct root_info
|
||||
int get_digits; // fraction of maximum possible accuracy required.
|
||||
// = digits * digits_accuracy
|
||||
// Vector of values (4) for each algorithm, TOMS748, Newton, Halley & Schroder.
|
||||
//std::vector< boost::int_least64_t> times; converted to int.
|
||||
//std::vector< std::int_least64_t> times; converted to int.
|
||||
std::vector<int> times; // arbitrary units (ticks).
|
||||
//boost::int_least64_t min_time = std::numeric_limits<boost::int_least64_t>::max(); // Used to normalize times (as int).
|
||||
//std::int_least64_t min_time = std::numeric_limits<std::int_least64_t>::max(); // Used to normalize times (as int).
|
||||
std::vector<double> normed_times;
|
||||
int min_time = (std::numeric_limits<int>::max)(); // Used to normalize times.
|
||||
std::vector<uintmax_t> iterations;
|
||||
@@ -203,8 +203,8 @@ T elliptic_root_noderiv(T radius, T arc)
|
||||
T guess = sqrt(arc * arc / 16 - radius * radius);
|
||||
T factor = 1.2; // How big steps to take when searching.
|
||||
|
||||
const boost::uintmax_t maxit = 50; // Limit to maximum iterations.
|
||||
boost::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
|
||||
const std::uintmax_t maxit = 50; // Limit to maximum iterations.
|
||||
std::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
|
||||
bool is_rising = true; // arc-length increases if one radii increases, so function is rising
|
||||
// Define a termination condition, stop when nearly all digits are correct, but allow for
|
||||
// the fact that we are returning a range, and must have some inaccuracy in the elliptic integral:
|
||||
@@ -268,8 +268,8 @@ T elliptic_root_1deriv(T radius, T arc)
|
||||
// Accuracy doubles at each step, so stop when just over half of the digits are
|
||||
// correct, and rely on that step to polish off the remainder:
|
||||
int get_digits = static_cast<int>(std::numeric_limits<T>::digits * 0.6);
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = newton_raphson_iterate(elliptic_root_functor_1deriv<T>(arc, radius), guess, min, max, get_digits, it);
|
||||
//<-
|
||||
iters = it;
|
||||
@@ -326,8 +326,8 @@ T elliptic_root_2deriv(T radius, T arc)
|
||||
// Accuracy triples at each step, so stop when just over one-third of the digits
|
||||
// are correct, and the last iteration will polish off the remaining digits:
|
||||
int get_digits = static_cast<int>(std::numeric_limits<T>::digits * 0.4);
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = halley_iterate(elliptic_root_functor_2deriv<T>(arc, radius), guess, min, max, get_digits, it);
|
||||
//<-
|
||||
iters = it;
|
||||
@@ -352,8 +352,8 @@ T elliptic_root_2deriv_s(T arc, T radius)
|
||||
|
||||
int digits = std::numeric_limits<T>::digits; // Maximum possible binary digits accuracy for type T.
|
||||
int get_digits = static_cast<int>(digits * digits_accuracy);
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = schroder_iterate(elliptic_root_functor_2deriv<T>(arc, radius), guess, min, max, get_digits, it);
|
||||
iters = it;
|
||||
|
||||
|
||||
@@ -141,11 +141,11 @@ struct root_info
|
||||
int get_digits; // fraction of maximum possible accuracy required.
|
||||
// = digits * digits_accuracy
|
||||
// Vector of values for each algorithm, std::cbrt, boost::math::cbrt, TOMS748, Newton, Halley.
|
||||
//std::vector< boost::int_least64_t> times; converted to int.
|
||||
//std::vector< std::int_least64_t> times; converted to int.
|
||||
std::vector<int> times;
|
||||
//boost::int_least64_t min_time = std::numeric_limits<boost::int_least64_t>::max(); // Used to normalize times (as int).
|
||||
//std::int_least64_t min_time = std::numeric_limits<std::int_least64_t>::max(); // Used to normalize times (as int).
|
||||
std::vector<double> normed_times;
|
||||
boost::int_least64_t min_time = (std::numeric_limits<boost::int_least64_t>::max)(); // Used to normalize times.
|
||||
std::int_least64_t min_time = (std::numeric_limits<std::int_least64_t>::max)(); // Used to normalize times.
|
||||
std::vector<uintmax_t> iterations;
|
||||
std::vector<long int> distances;
|
||||
std::vector<cpp_bin_float_100> full_results;
|
||||
@@ -215,8 +215,8 @@ T cbrt_noderiv(T x)
|
||||
|
||||
T factor = 2; // How big steps to take when searching.
|
||||
|
||||
const boost::uintmax_t maxit = 50; // Limit to maximum iterations.
|
||||
boost::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
|
||||
const std::uintmax_t maxit = 50; // Limit to maximum iterations.
|
||||
std::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
|
||||
bool is_rising = true; // So if result if guess^3 is too low, then try increasing guess.
|
||||
// Some fraction of digits is used to control how accurate to try to make the result.
|
||||
int get_digits = static_cast<int>(std::numeric_limits<T>::digits - 2);
|
||||
@@ -265,8 +265,8 @@ T cbrt_deriv(T x)
|
||||
T min = guess / 2; // Minimum possible value is half our guess.
|
||||
T max = 2 * guess; // Maximum possible value is twice our guess.
|
||||
int get_digits = static_cast<int>(std::numeric_limits<T>::digits * 0.6);
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = newton_raphson_iterate(cbrt_functor_deriv<T>(x), guess, min, max, get_digits, it);
|
||||
iters = it;
|
||||
return result;
|
||||
@@ -310,8 +310,8 @@ T cbrt_2deriv(T x)
|
||||
T max = 2 * guess; // Maximum possible value is twice our guess.
|
||||
// digits used to control how accurate to try to make the result.
|
||||
int get_digits = static_cast<int>(std::numeric_limits<T>::digits * 0.4);
|
||||
boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = halley_iterate(cbrt_functor_2deriv<T>(x), guess, min, max, get_digits, it);
|
||||
iters = it;
|
||||
return result;
|
||||
@@ -337,8 +337,8 @@ T cbrt_2deriv_s(T x)
|
||||
T max = 2 * guess; // Maximum possible value is twice our guess.
|
||||
// digits used to control how accurate to try to make the result.
|
||||
int get_digits = static_cast<int>(std::numeric_limits<T>::digits * 0.4);
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = schroder_iterate(cbrt_functor_2deriv<T>(x), guess, min, max, get_digits, it);
|
||||
iters = it;
|
||||
return result;
|
||||
|
||||
@@ -127,8 +127,8 @@ T cbrt_noderiv(T x)
|
||||
T guess = ldexp(1., exponent/3); // Rough guess is to divide the exponent by three.
|
||||
T factor = 2; // How big steps to take when searching.
|
||||
|
||||
const boost::uintmax_t maxit = 20; // Limit to maximum iterations.
|
||||
boost::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
|
||||
const std::uintmax_t maxit = 20; // Limit to maximum iterations.
|
||||
std::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
|
||||
bool is_rising = true; // So if result if guess^3 is too low, then try increasing guess.
|
||||
int digits = std::numeric_limits<T>::digits; // Maximum possible binary digits accuracy for type T.
|
||||
// Some fraction of digits is used to control how accurate to try to make the result.
|
||||
@@ -145,7 +145,7 @@ T cbrt_noderiv(T x)
|
||||
/*`
|
||||
|
||||
[note The final parameter specifying a maximum number of iterations is optional.
|
||||
However, it defaults to `boost::uintmax_t maxit = (std::numeric_limits<boost::uintmax_t>::max)();`
|
||||
However, it defaults to `std::uintmax_t maxit = (std::numeric_limits<std::uintmax_t>::max)();`
|
||||
which is `18446744073709551615` and is more than anyone would wish to wait for!
|
||||
|
||||
So it may be wise to chose some reasonable estimate of how many iterations may be needed,
|
||||
@@ -235,8 +235,8 @@ T cbrt_deriv(T x)
|
||||
const int digits = std::numeric_limits<T>::digits; // Maximum possible binary digits accuracy for type T.
|
||||
int get_digits = static_cast<int>(digits * 0.6); // Accuracy doubles with each step, so stop when we have
|
||||
// just over half the digits correct.
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = newton_raphson_iterate(cbrt_functor_deriv<T>(x), guess, min, max, get_digits, it);
|
||||
return result;
|
||||
}
|
||||
@@ -295,7 +295,7 @@ T cbrt_2deriv(T x)
|
||||
// digits used to control how accurate to try to make the result.
|
||||
int get_digits = static_cast<int>(digits * 0.4); // Accuracy triples with each step, so stop when just
|
||||
// over one third of the digits are correct.
|
||||
boost::uintmax_t maxit = 20;
|
||||
std::uintmax_t maxit = 20;
|
||||
T result = halley_iterate(cbrt_functor_2deriv<T>(x), guess, min, max, get_digits, maxit);
|
||||
return result;
|
||||
}
|
||||
@@ -319,7 +319,7 @@ T cbrt_2deriv_lambda(T x)
|
||||
// digits used to control how accurate to try to make the result.
|
||||
int get_digits = static_cast<int>(digits * 0.4); // Accuracy triples with each step, so stop when just
|
||||
// over one third of the digits are correct.
|
||||
boost::uintmax_t maxit = 20;
|
||||
std::uintmax_t maxit = 20;
|
||||
T result = halley_iterate(
|
||||
// lambda function:
|
||||
[x](const T& g){ return std::make_tuple(g * g * g - x, 3 * g * g, 6 * g); },
|
||||
@@ -421,8 +421,8 @@ T fifth_2deriv(T x)
|
||||
T max = ldexp(2., exponent / 5); // Maximum possible value is twice our guess.
|
||||
// Stop when slightly more than one of the digits are correct:
|
||||
const int digits = static_cast<int>(std::numeric_limits<T>::digits * 0.4);
|
||||
const boost::uintmax_t maxit = 50;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 50;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = halley_iterate(fifth_functor_2deriv<T>(x), guess, min, max, digits, it);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -172,18 +172,18 @@ T fifth_noderiv(T x)
|
||||
// int digits = 3 * std::numeric_limits<T>::digits / 4; // 3/4 maximum possible binary digits accuracy for type T.
|
||||
int digits = std::numeric_limits<T>::digits; // Maximum possible binary digits accuracy for type T.
|
||||
|
||||
//boost::uintmax_t maxit = (std::numeric_limits<boost::uintmax_t>::max)();
|
||||
// (std::numeric_limits<boost::uintmax_t>::max)() = 18446744073709551615
|
||||
//std::uintmax_t maxit = (std::numeric_limits<std::uintmax_t>::max)();
|
||||
// (std::numeric_limits<std::uintmax_t>::max)() = 18446744073709551615
|
||||
// which is more than anyone might wish to wait for!!!
|
||||
// so better to choose some reasonable estimate of how many iterations may be needed.
|
||||
|
||||
const boost::uintmax_t maxit = 50; // Chosen max iterations,
|
||||
const std::uintmax_t maxit = 50; // Chosen max iterations,
|
||||
// but updated on exit with actual iteration count.
|
||||
|
||||
// We could also have used a maximum iterations provided by any policy:
|
||||
// boost::uintmax_t max_it = policies::get_max_root_iterations<Policy>();
|
||||
// std::uintmax_t max_it = policies::get_max_root_iterations<Policy>();
|
||||
|
||||
boost::uintmax_t it = maxit; // Initially our chosen max iterations,
|
||||
std::uintmax_t it = maxit; // Initially our chosen max iterations,
|
||||
|
||||
bool is_rising = true; // So if result if guess^5 is too low, try increasing guess.
|
||||
eps_tolerance<double> tol(digits);
|
||||
@@ -289,8 +289,8 @@ T fifth_1deriv(T x)
|
||||
// digits used to control how accurate to try to make the result.
|
||||
int digits = std::numeric_limits<T>::digits; // Maximum possible binary digits accuracy for type T.
|
||||
|
||||
const boost::uintmax_t maxit = 20; // Optionally limit the number of iterations.
|
||||
boost::uintmax_t it = maxit; // limit the number of iterations.
|
||||
const std::uintmax_t maxit = 20; // Optionally limit the number of iterations.
|
||||
std::uintmax_t it = maxit; // limit the number of iterations.
|
||||
//cout << "Max Iterations " << maxit << endl; //
|
||||
T result = newton_raphson_iterate(fifth_functor_1stderiv<T>(x), guess, min, max, digits, it);
|
||||
// Can check and show how many iterations (updated by newton_raphson_iterate).
|
||||
@@ -302,8 +302,8 @@ T fifth_1deriv(T x)
|
||||
|
||||
// int get_digits = (digits * 2) /3; // Two thirds of maximum possible accuracy.
|
||||
|
||||
//boost::uintmax_t maxit = (std::numeric_limits<boost::uintmax_t>::max)();
|
||||
// the default (std::numeric_limits<boost::uintmax_t>::max)() = 18446744073709551615
|
||||
//std::uintmax_t maxit = (std::numeric_limits<std::uintmax_t>::max)();
|
||||
// the default (std::numeric_limits<std::uintmax_t>::max)() = 18446744073709551615
|
||||
// which is more than we might wish to wait for!!! so we can reduce it
|
||||
|
||||
/*`
|
||||
@@ -357,8 +357,8 @@ T fifth_2deriv(T x)
|
||||
T max = ldexp(2., exponent / 5); // Maximum possible value is twice our guess.
|
||||
|
||||
int digits = std::numeric_limits<T>::digits / 2; // Half maximum possible binary digits accuracy for type T.
|
||||
const boost::uintmax_t maxit = 50;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 50;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = halley_iterate(fifth_functor_2deriv<T>(x), guess, min, max, digits, it);
|
||||
// Can show how many iterations (updated by halley_iterate).
|
||||
cout << it << " iterations (from max of " << maxit << ")" << endl;
|
||||
|
||||
@@ -69,8 +69,8 @@ T cbrt_2deriv(T x)
|
||||
#endif
|
||||
|
||||
int digits = std::numeric_limits<T>::digits / 2; // Half maximum possible binary digits accuracy for type T.
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = halley_iterate(cbrt_functor_2deriv<T>(x), guess, min, max, digits, it);
|
||||
// Can show how many iterations (updated by halley_iterate).
|
||||
// std::cout << "Iterations " << it << " (from max of "<< maxit << ")." << std::endl;
|
||||
@@ -135,8 +135,8 @@ T nth_2deriv(T x)
|
||||
T max = ldexp(static_cast<T>(2.), exponent / n); // Maximum possible value is twice our guess.
|
||||
|
||||
int digits = std::numeric_limits<T>::digits / 2; // Half maximum possible binary digits accuracy for type T.
|
||||
const boost::uintmax_t maxit = 50;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 50;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = halley_iterate(nth_functor_2deriv<n, T>(x), guess, min, max, digits, it);
|
||||
// Can show how many iterations (updated by halley_iterate).
|
||||
std::cout << it << " iterations (from max of " << maxit << ")" << std::endl;
|
||||
|
||||
@@ -105,8 +105,8 @@ T nth_2deriv(T x)
|
||||
|
||||
int digits = std::numeric_limits<T>::digits * 0.4; // Accuracy triples with each step, so stop when
|
||||
// slightly more than one third of the digits are correct.
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = halley_iterate(nth_functor_2deriv<N, T>(x), guess, min, max, digits, it);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ private:
|
||||
//] [/root_finding_noderiv_1
|
||||
|
||||
template <class T>
|
||||
boost::uintmax_t cbrt_noderiv(T x, T guess)
|
||||
std::uintmax_t cbrt_noderiv(T x, T guess)
|
||||
{
|
||||
// return cube root of x using bracket_and_solve (no derivatives).
|
||||
using namespace std; // Help ADL of std functions.
|
||||
@@ -42,8 +42,8 @@ boost::uintmax_t cbrt_noderiv(T x, T guess)
|
||||
|
||||
T factor = 2; // How big steps to take when searching.
|
||||
|
||||
const boost::uintmax_t maxit = 20; // Limit to maximum iterations.
|
||||
boost::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
|
||||
const std::uintmax_t maxit = 20; // Limit to maximum iterations.
|
||||
std::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
|
||||
bool is_rising = true; // So if result if guess^3 is too low, then try increasing guess.
|
||||
int digits = std::numeric_limits<T>::digits; // Maximum possible binary digits accuracy for type T.
|
||||
// Some fraction of digits is used to control how accurate to try to make the result.
|
||||
@@ -75,7 +75,7 @@ private:
|
||||
};
|
||||
|
||||
template <class T>
|
||||
boost::uintmax_t cbrt_deriv(T x, T guess)
|
||||
std::uintmax_t cbrt_deriv(T x, T guess)
|
||||
{
|
||||
// return cube root of x using 1st derivative and Newton_Raphson.
|
||||
using namespace boost::math::tools;
|
||||
@@ -84,8 +84,8 @@ boost::uintmax_t cbrt_deriv(T x, T guess)
|
||||
const int digits = std::numeric_limits<T>::digits; // Maximum possible binary digits accuracy for type T.
|
||||
int get_digits = static_cast<int>(digits * 0.6); // Accuracy doubles with each step, so stop when we have
|
||||
// just over half the digits correct.
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
newton_raphson_iterate(cbrt_functor_deriv<T>(x), guess, min, max, get_digits, it);
|
||||
return it;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ private:
|
||||
};
|
||||
|
||||
template <class T>
|
||||
boost::uintmax_t cbrt_2deriv(T x, T guess)
|
||||
std::uintmax_t cbrt_2deriv(T x, T guess)
|
||||
{
|
||||
// return cube root of x using 1st and 2nd derivatives and Halley.
|
||||
//using namespace std; // Help ADL of std functions.
|
||||
@@ -122,13 +122,13 @@ boost::uintmax_t cbrt_2deriv(T x, T guess)
|
||||
// digits used to control how accurate to try to make the result.
|
||||
int get_digits = static_cast<int>(digits * 0.4); // Accuracy triples with each step, so stop when just
|
||||
// over one third of the digits are correct.
|
||||
boost::uintmax_t maxit = 20;
|
||||
std::uintmax_t maxit = 20;
|
||||
halley_iterate(cbrt_functor_2deriv<T>(x), guess, min, max, get_digits, maxit);
|
||||
return maxit;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
boost::uintmax_t cbrt_2deriv_s(T x, T guess)
|
||||
std::uintmax_t cbrt_2deriv_s(T x, T guess)
|
||||
{
|
||||
// return cube root of x using 1st and 2nd derivatives and Halley.
|
||||
//using namespace std; // Help ADL of std functions.
|
||||
@@ -139,7 +139,7 @@ boost::uintmax_t cbrt_2deriv_s(T x, T guess)
|
||||
// digits used to control how accurate to try to make the result.
|
||||
int get_digits = static_cast<int>(digits * 0.4); // Accuracy triples with each step, so stop when just
|
||||
// over one third of the digits are correct.
|
||||
boost::uintmax_t maxit = 20;
|
||||
std::uintmax_t maxit = 20;
|
||||
schroder_iterate(cbrt_functor_2deriv<T>(x), guess, min, max, get_digits, maxit);
|
||||
return maxit;
|
||||
}
|
||||
@@ -165,15 +165,15 @@ private:
|
||||
}; // template <class T> struct elliptic_root_functor_noderiv
|
||||
|
||||
template <class T = double>
|
||||
boost::uintmax_t elliptic_root_noderiv(T radius, T arc, T guess)
|
||||
std::uintmax_t elliptic_root_noderiv(T radius, T arc, T guess)
|
||||
{ // return the other radius of an ellipse, given one radii and the arc-length
|
||||
using namespace std; // Help ADL of std functions.
|
||||
using namespace boost::math::tools; // For bracket_and_solve_root.
|
||||
|
||||
T factor = 2; // How big steps to take when searching.
|
||||
|
||||
const boost::uintmax_t maxit = 50; // Limit to maximum iterations.
|
||||
boost::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
|
||||
const std::uintmax_t maxit = 50; // Limit to maximum iterations.
|
||||
std::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
|
||||
bool is_rising = true; // arc-length increases if one radii increases, so function is rising
|
||||
// Define a termination condition, stop when nearly all digits are correct, but allow for
|
||||
// the fact that we are returning a range, and must have some inaccuracy in the elliptic integral:
|
||||
@@ -215,7 +215,7 @@ private:
|
||||
}; // struct elliptic_root__functor_1deriv
|
||||
|
||||
template <class T = double>
|
||||
boost::uintmax_t elliptic_root_1deriv(T radius, T arc, T guess)
|
||||
std::uintmax_t elliptic_root_1deriv(T radius, T arc, T guess)
|
||||
{
|
||||
using namespace std; // Help ADL of std functions.
|
||||
using namespace boost::math::tools; // For newton_raphson_iterate.
|
||||
@@ -228,8 +228,8 @@ boost::uintmax_t elliptic_root_1deriv(T radius, T arc, T guess)
|
||||
// Accuracy doubles at each step, so stop when just over half of the digits are
|
||||
// correct, and rely on that step to polish off the remainder:
|
||||
int get_digits = static_cast<int>(std::numeric_limits<T>::digits * 0.6);
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
newton_raphson_iterate(elliptic_root_functor_1deriv<T>(arc, radius), guess, min, max, get_digits, it);
|
||||
return it;
|
||||
}
|
||||
@@ -264,7 +264,7 @@ private:
|
||||
};
|
||||
|
||||
template <class T = double>
|
||||
boost::uintmax_t elliptic_root_2deriv(T radius, T arc, T guess)
|
||||
std::uintmax_t elliptic_root_2deriv(T radius, T arc, T guess)
|
||||
{
|
||||
using namespace std; // Help ADL of std functions.
|
||||
using namespace boost::math::tools; // For halley_iterate.
|
||||
@@ -277,8 +277,8 @@ boost::uintmax_t elliptic_root_2deriv(T radius, T arc, T guess)
|
||||
// Accuracy triples at each step, so stop when just over one-third of the digits
|
||||
// are correct, and the last iteration will polish off the remaining digits:
|
||||
int get_digits = static_cast<int>(std::numeric_limits<T>::digits * 0.4);
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
halley_iterate(elliptic_root_functor_2deriv<T>(arc, radius), guess, min, max, get_digits, it);
|
||||
return it;
|
||||
} // nth_2deriv Halley
|
||||
@@ -286,7 +286,7 @@ boost::uintmax_t elliptic_root_2deriv(T radius, T arc, T guess)
|
||||
// Using 1st and 2nd derivatives using Schroder algorithm.
|
||||
|
||||
template <class T = double>
|
||||
boost::uintmax_t elliptic_root_2deriv_s(T radius, T arc, T guess)
|
||||
std::uintmax_t elliptic_root_2deriv_s(T radius, T arc, T guess)
|
||||
{ // return nth root of x using 1st and 2nd derivatives and Schroder.
|
||||
|
||||
using namespace std; // Help ADL of std functions.
|
||||
@@ -299,8 +299,8 @@ boost::uintmax_t elliptic_root_2deriv_s(T radius, T arc, T guess)
|
||||
|
||||
int digits = std::numeric_limits<T>::digits; // Maximum possible binary digits accuracy for type T.
|
||||
int get_digits = static_cast<int>(digits * 0.4);
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
schroder_iterate(elliptic_root_functor_2deriv<T>(arc, radius), guess, min, max, get_digits, it);
|
||||
return it;
|
||||
} // T elliptic_root_2deriv_s Schroder
|
||||
|
||||
@@ -135,9 +135,9 @@ struct root_info
|
||||
int get_digits; // fraction of maximum possible accuracy required.
|
||||
// = digits * digits_accuracy
|
||||
// Vector of values (4) for each algorithm, TOMS748, Newton, Halley & Schroder.
|
||||
//std::vector< boost::int_least64_t> times; converted to int.
|
||||
//std::vector< std::int_least64_t> times; converted to int.
|
||||
std::vector<int> times; // arbitrary units (ticks).
|
||||
//boost::int_least64_t min_time = std::numeric_limits<boost::int_least64_t>::max(); // Used to normalize times (as int).
|
||||
//std::int_least64_t min_time = std::numeric_limits<std::int_least64_t>::max(); // Used to normalize times (as int).
|
||||
std::vector<double> normed_times;
|
||||
int min_time = (std::numeric_limits<int>::max)(); // Used to normalize times.
|
||||
std::vector<uintmax_t> iterations;
|
||||
@@ -205,8 +205,8 @@ T nth_root_noderiv(T x)
|
||||
|
||||
T factor = 2; // How big steps to take when searching.
|
||||
|
||||
const boost::uintmax_t maxit = 50; // Limit to maximum iterations.
|
||||
boost::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
|
||||
const std::uintmax_t maxit = 50; // Limit to maximum iterations.
|
||||
std::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
|
||||
bool is_rising = true; // So if result if guess^3 is too low, then try increasing guess.
|
||||
// Some fraction of digits is used to control how accurate to try to make the result.
|
||||
int get_digits = std::numeric_limits<T>::digits - 2;
|
||||
@@ -260,8 +260,8 @@ T nth_root_1deriv(T x)
|
||||
|
||||
int digits = std::numeric_limits<T>::digits; // Maximum possible binary digits accuracy for type T.
|
||||
int get_digits = static_cast<int>(digits * 0.6);
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = newton_raphson_iterate(nth_root_functor_1deriv<N, T>(x), guess, min, max, get_digits, it);
|
||||
iters = it;
|
||||
return result;
|
||||
@@ -312,8 +312,8 @@ T nth_root_2deriv(T x)
|
||||
|
||||
int digits = std::numeric_limits<T>::digits; // Maximum possible binary digits accuracy for type T.
|
||||
int get_digits = static_cast<int>(digits * 0.4);
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = halley_iterate(nth_root_functor_2deriv<N, T>(x), guess, min, max, get_digits, it);
|
||||
iters = it;
|
||||
|
||||
@@ -340,8 +340,8 @@ T nth_root_2deriv_s(T x)
|
||||
T max = static_cast<T>(ldexp(static_cast<guess_type>(2.), exponent / N)); // Maximum possible value is twice our guess.
|
||||
|
||||
int get_digits = static_cast<int>(std::numeric_limits<T>::digits * 0.4);
|
||||
const boost::uintmax_t maxit = 20;
|
||||
boost::uintmax_t it = maxit;
|
||||
const std::uintmax_t maxit = 20;
|
||||
std::uintmax_t it = maxit;
|
||||
T result = schroder_iterate(nth_root_functor_2deriv<N, T>(x), guess, min, max, get_digits, it);
|
||||
iters = it;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ T log1p(T x)
|
||||
// Construct the series functor:
|
||||
log1p_series<T> s(x);
|
||||
// Set a limit on how many iterations we permit:
|
||||
boost::uintmax_t max_iter = 1000;
|
||||
std::uintmax_t max_iter = 1000;
|
||||
// Add it up, with enough precision for full machine precision:
|
||||
return boost::math::tools::sum_series(s, std::numeric_limits<T>::epsilon(), max_iter);
|
||||
}
|
||||
@@ -89,7 +89,7 @@ std::complex<T> log1p(std::complex<T> x)
|
||||
// Construct the series functor:
|
||||
log1p_series<std::complex<T> > s(x);
|
||||
// Set a limit on how many iterations we permit:
|
||||
boost::uintmax_t max_iter = 1000;
|
||||
std::uintmax_t max_iter = 1000;
|
||||
// Add it up, with enough precision for full machine precision:
|
||||
return boost::math::tools::sum_series(s, std::complex<T>(std::numeric_limits<T>::epsilon()), max_iter);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user