bug #1521: avoid signalling NaN in hypot and make it std::complex<> friendly.

(grafted from e116f6847e
)
This commit is contained in:
Gael Guennebaud
2018-04-04 13:47:23 +02:00
parent 892c0a79ce
commit b18e2d422b
2 changed files with 20 additions and 25 deletions

View File

@@ -71,6 +71,25 @@ T generic_fast_tanh_float(const T& a_x)
return pdiv(p, q);
}
template<typename Scalar>
struct hypot_impl
{
typedef typename NumTraits<Scalar>::Real RealScalar;
static inline RealScalar run(const Scalar& x, const Scalar& y)
{
EIGEN_USING_STD_MATH(abs);
EIGEN_USING_STD_MATH(sqrt);
RealScalar _x = abs(x);
RealScalar _y = abs(y);
RealScalar p, qp;
p = numext::maxi(_x,_y);
if(p==RealScalar(0)) return RealScalar(0);
qp = numext::mini(_y,_x) / p;
return p * sqrt(RealScalar(1) + qp*qp);
}
};
} // end namespace internal
} // end namespace Eigen