aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/MathFunctionsImpl.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2018-04-04 13:47:23 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2018-04-04 13:47:23 +0200
commite116f6847e3cd9d16ea3be14c2b7efbd0a1c2b0b (patch)
tree30a2a845a5a479a2dec68bdfe21bc923b164028b /Eigen/src/Core/MathFunctionsImpl.h
parent73729025a4740d344bae98dfbae36a69405e217f (diff)
bug #1521: avoid signalling NaN in hypot and make it std::complex<> friendly.
Diffstat (limited to 'Eigen/src/Core/MathFunctionsImpl.h')
-rw-r--r--Eigen/src/Core/MathFunctionsImpl.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/Eigen/src/Core/MathFunctionsImpl.h b/Eigen/src/Core/MathFunctionsImpl.h
index ae1386b4c..034cfad7b 100644
--- a/Eigen/src/Core/MathFunctionsImpl.h
+++ b/Eigen/src/Core/MathFunctionsImpl.h
@@ -66,6 +66,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