aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2014-09-02 16:09:39 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2014-09-02 16:09:39 +0200
commit42e27d41a2014043799b44b68b0d5644629279ba (patch)
tree00c431910d5af6b08540e7e68a1d8dc1afed5660 /Eigen
parenta44a343f034eb915f9ad6dcd69e4be534d48bbe5 (diff)
Fix hypot() and hypotNorm() wrt NaN and INF values.
Diffstat (limited to 'Eigen')
-rw-r--r--Eigen/src/Core/MathFunctions.h15
-rw-r--r--Eigen/src/Core/functors/BinaryFunctors.h14
2 files changed, 22 insertions, 7 deletions
diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h
index 20fc2be74..5df1fbfec 100644
--- a/Eigen/src/Core/MathFunctions.h
+++ b/Eigen/src/Core/MathFunctions.h
@@ -308,10 +308,17 @@ struct hypot_impl
using std::sqrt;
RealScalar _x = abs(x);
RealScalar _y = abs(y);
- RealScalar p = (max)(_x, _y);
- if(p==RealScalar(0)) return 0;
- RealScalar q = (min)(_x, _y);
- RealScalar qp = q/p;
+ Scalar p, qp;
+ if(_x>_y)
+ {
+ p = _x;
+ qp = _y / p;
+ }
+ else
+ {
+ p = _y;
+ qp = _x / p;
+ }
return p * sqrt(RealScalar(1) + qp*qp);
}
};
diff --git a/Eigen/src/Core/functors/BinaryFunctors.h b/Eigen/src/Core/functors/BinaryFunctors.h
index ba094f5d1..157d075a7 100644
--- a/Eigen/src/Core/functors/BinaryFunctors.h
+++ b/Eigen/src/Core/functors/BinaryFunctors.h
@@ -167,9 +167,17 @@ template<typename Scalar> struct scalar_hypot_op {
EIGEN_USING_STD_MATH(max);
EIGEN_USING_STD_MATH(min);
using std::sqrt;
- Scalar p = (max)(_x, _y);
- Scalar q = (min)(_x, _y);
- Scalar qp = q/p;
+ Scalar p, qp;
+ if(_x>_y)
+ {
+ p = _x;
+ qp = _y / p;
+ }
+ else
+ {
+ p = _y;
+ qp = _x / p;
+ }
return p * sqrt(Scalar(1) + qp*qp);
}
};