diff --git a/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h b/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h index ee1f16b7e..d6c2a29de 100644 --- a/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h +++ b/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h @@ -101,7 +101,7 @@ class AutoDiffScalar /** Conversion from a scalar constant to an active scalar. * The derivatives are set to zero. */ - explicit AutoDiffScalar(const Real& value) + /*explicit*/ AutoDiffScalar(const Real& value) : m_value(value) { if(m_derivatives.size()>0) @@ -228,6 +228,12 @@ class AutoDiffScalar (a - b.value(), -b.derivatives()); } + inline AutoDiffScalar& operator-=(const Scalar& other) + { + value() -= other; + return *this; + } + template inline const AutoDiffScalar, const DerType,const typename internal::remove_all::type> > operator-(const AutoDiffScalar& other) const @@ -299,7 +305,7 @@ class AutoDiffScalar { return AutoDiffScalar, const DerType> >( other / a.value(), - a.derivatives() * (-Scalar(1)/other)); + a.derivatives() * (Scalar(-other) / (a.value()*a.value()))); } // inline const AutoDiffScalar, DerType>::Type > @@ -362,6 +368,19 @@ class AutoDiffScalar return *this; } + inline AutoDiffScalar& operator/=(const Scalar& other) + { + *this = *this / other; + return *this; + } + + template + inline AutoDiffScalar& operator/=(const AutoDiffScalar& other) + { + *this = *this / other; + return *this; + } + protected: Scalar m_value; DerType m_derivatives; @@ -519,6 +538,16 @@ template inline const AutoDiffScalar& real(const AutoDiffScalar& x) { return x; } template inline typename DerType::Scalar imag(const AutoDiffScalar&) { return 0.; } +template +inline AutoDiffScalar min(const AutoDiffScalar& x, const T& y) { return (x <= y ? x : y); } +template +inline AutoDiffScalar max(const AutoDiffScalar& x, const T& y) { return (x >= y ? x : y); } +template +inline AutoDiffScalar min(const T& x, const AutoDiffScalar& y) { return (x < y ? x : y); } +template +inline AutoDiffScalar max(const T& x, const AutoDiffScalar& y) { return (x > y ? x : y); } + +#define sign(x) x >= 0 ? 1 : -1 // required for abs function below EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs, using std::abs;