Changed calculation of upper and lower safe bounds to avoid problems with std::sqrt(long double) returning infinities.