mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-27 07:29:52 +08:00
bug #1521: avoid signalling NaN in hypot and make it std::complex<> friendly.
This commit is contained in:
parent
73729025a4
commit
e116f6847e
@ -347,31 +347,7 @@ struct norm1_retval
|
|||||||
* Implementation of hypot *
|
* Implementation of hypot *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
template<typename Scalar>
|
template<typename Scalar> struct hypot_impl;
|
||||||
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);
|
|
||||||
Scalar p, qp;
|
|
||||||
if(_x>_y)
|
|
||||||
{
|
|
||||||
p = _x;
|
|
||||||
qp = _y / p;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p = _y;
|
|
||||||
qp = _x / p;
|
|
||||||
}
|
|
||||||
if(p==RealScalar(0)) return RealScalar(0);
|
|
||||||
return p * sqrt(RealScalar(1) + qp*qp);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Scalar>
|
template<typename Scalar>
|
||||||
struct hypot_retval
|
struct hypot_retval
|
||||||
|
@ -66,6 +66,25 @@ T generic_fast_tanh_float(const T& a_x)
|
|||||||
return pdiv(p, q);
|
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 internal
|
||||||
|
|
||||||
} // end namespace Eigen
|
} // end namespace Eigen
|
||||||
|
Loading…
Reference in New Issue
Block a user