Introduce EIGEN_PI, get rid of M_PI and acos(-1.0)

This commit is contained in:
Gael Guennebaud
2015-06-10 17:12:10 +02:00
parent 9756c7fb4d
commit d93ba137f2
6 changed files with 29 additions and 31 deletions

View File

@@ -10,6 +10,9 @@
#ifndef EIGEN_MATHFUNCTIONS_H
#define EIGEN_MATHFUNCTIONS_H
// source: http://www.geom.uiuc.edu/~huberty/math5337/groupe/digits.html
#define EIGEN_PI 3.141592653589793238462643383279502884197169399375105820974944592307816406
namespace Eigen {
// On WINCE, std::abs is defined for int only, so let's defined our own overloads:
@@ -415,8 +418,7 @@ struct round_retval
EIGEN_DEVICE_FUNC
static inline RealScalar run(const Scalar& x)
{
const double pi = std::acos(-1.0);
return (x < 0.0) ? pi : 0.0; }
return (x < 0.0) ? EIGEN_PI : 0.0; }
};
template<typename Scalar>

View File

@@ -55,7 +55,7 @@ MatrixBase<Derived>::eulerAngles(Index a0, Index a1, Index a2) const
res[0] = atan2(coeff(j,i), coeff(k,i));
if((odd && res[0]<Scalar(0)) || ((!odd) && res[0]>Scalar(0)))
{
res[0] = (res[0] > Scalar(0)) ? res[0] - Scalar(M_PI) : res[0] + Scalar(M_PI);
res[0] = (res[0] > Scalar(0)) ? res[0] - Scalar(EIGEN_PI) : res[0] + Scalar(EIGEN_PI);
Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm();
res[1] = -atan2(s2, coeff(i,i));
}
@@ -84,7 +84,7 @@ MatrixBase<Derived>::eulerAngles(Index a0, Index a1, Index a2) const
res[0] = atan2(coeff(j,k), coeff(k,k));
Scalar c2 = Vector2(coeff(i,i), coeff(i,j)).norm();
if((odd && res[0]<Scalar(0)) || ((!odd) && res[0]>Scalar(0))) {
res[0] = (res[0] > Scalar(0)) ? res[0] - Scalar(M_PI) : res[0] + Scalar(M_PI);
res[0] = (res[0] > Scalar(0)) ? res[0] - Scalar(EIGEN_PI) : res[0] + Scalar(EIGEN_PI);
res[1] = atan2(-coeff(i,k), -c2);
}
else