Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions include/boost/math/complex/details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <cmath>
#include <complex>
#include <limits>
#include <algorithm>
#include <boost/math/special_functions/sign.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
#include <boost/math/constants/constants.hpp>
Expand Down Expand Up @@ -41,13 +42,12 @@ inline std::complex<T> mult_minus_i(const std::complex<T>& t)
template <class T>
inline T safe_max(T t)
{
return std::sqrt((std::numeric_limits<T>::max)()) / t;
}
inline long double safe_max(long double t)
{
// long double sqrt often returns infinity due to
// insufficient internal precision:
return std::sqrt((std::numeric_limits<double>::max)()) / t;
static const T max_val = (std::numeric_limits<T>::max)();
static const T min_val = (std::numeric_limits<T>::min)();

// Prevent division by zero and overflow
T denominator = (std::max)(std::abs(t), min_val);
return std::sqrt(max_val) / denominator;
}

template <class T>
Expand Down