Skip to content

second_order_root_finder (near) infinite loop #776

@TFiFiE

Description

@TFiFiE

halley_iterate and schroder_iterate can get stuck in a (virtually) infinite loop even when given a limited max_iter, because in the function:

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:
delta = bracket_root_towards_min(f, guess, f0, min, max, count);

delta = bracket_root_towards_max(f, guess, f0, min, max, count);

where it will wrap around by any of:
while (--count && ((f_current < 0) == (f0 < 0)))

while (--count && ((f_current < 0) == (f0 < 0)))

while (--count && ((f_current < 0) == (f0 < 0)))

while (--count && ((f_current < 0) == (f0 < 0)))

becoming std::numeric_limits<boost::uintmax_t>::max() before reaching:
} while(count && (fabs(result * factor) < fabs(delta)));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions