-
Notifications
You must be signed in to change notification settings - Fork 250
Description
halley_iterate and schroder_iterate can get stuck in a (virtually) infinite loop even when given a limited max_iter, because in the function:
math/include/boost/math/tools/roots.hpp
Line 483 in b22105f
| T second_order_root_finder(F f, T guess, T min, T max, int digits, std::uintmax_t& max_iter) noexcept(policies::is_noexcept_error_policy<policies::policy<> >::value&& BOOST_MATH_IS_FLOAT(T) && noexcept(std::declval<F>()(std::declval<T>()))) |
the variable
count might already be zero when either of the following functions is called:math/include/boost/math/tools/roots.hpp
Line 612 in b22105f
| delta = bracket_root_towards_min(f, guess, f0, min, max, count); |
math/include/boost/math/tools/roots.hpp
Line 638 in b22105f
| delta = bracket_root_towards_max(f, guess, f0, min, max, count); |
where it will wrap around by any of:
math/include/boost/math/tools/roots.hpp
Line 383 in b22105f
| while (--count && ((f_current < 0) == (f0 < 0))) |
math/include/boost/math/tools/roots.hpp
Line 402 in b22105f
| while (--count && ((f_current < 0) == (f0 < 0))) |
math/include/boost/math/tools/roots.hpp
Line 439 in b22105f
| while (--count && ((f_current < 0) == (f0 < 0))) |
math/include/boost/math/tools/roots.hpp
Line 458 in b22105f
| while (--count && ((f_current < 0) == (f0 < 0))) |
becoming
std::numeric_limits<boost::uintmax_t>::max() before reaching:math/include/boost/math/tools/roots.hpp
Line 662 in b22105f
| } while(count && (fabs(result * factor) < fabs(delta))); |