2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-26 18:52:10 +00:00

roots.hpp: clean up code so that there is no division by zero possible.

Fixes: https://github.com/boostorg/math/issues/160.
This commit is contained in:
jzmaddock
2018-11-30 19:54:34 +00:00
parent 24694847dc
commit db408fde2b

View File

@@ -514,9 +514,10 @@ namespace detail{
template <class T>
static T step(const T& x, const T& f0, const T& f1, const T& f2) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(T))
{
using std::fabs;
T ratio = f0 / f1;
T delta;
if(ratio / x < 0.1)
if((x != 0) && (fabs(ratio / x) < 0.1))
{
delta = ratio + (f2 / (2 * f1)) * ratio * ratio;
// check second derivative doesn't over compensate: