Simplify MatrixPower::split

This commit is contained in:
Chen-Pang He 2013-07-20 17:49:38 +08:00
parent 4b780553e0
commit c587e63631

View File

@ -381,7 +381,7 @@ class MatrixPower : internal::noncopyable
RealScalar m_conditionNumber; RealScalar m_conditionNumber;
Index m_rank, m_nulls; Index m_rank, m_nulls;
RealScalar split(RealScalar, RealScalar*); void split(RealScalar&, RealScalar&);
void initialize(); void initialize();
template<typename ResultType> template<typename ResultType>
@ -414,26 +414,26 @@ void MatrixPower<MatrixType>::compute(ResultType& res, RealScalar p)
res(0,0) = std::pow(m_A.coeff(0,0), p); res(0,0) = std::pow(m_A.coeff(0,0), p);
break; break;
default: default:
RealScalar intpart, x = split(p, &intpart); RealScalar intpart;
split(p, intpart);
computeIntPower(res, intpart); computeIntPower(res, intpart);
if (x) computeFracPower(res, x); if (p) computeFracPower(res, p);
} }
} }
template<typename MatrixType> template<typename MatrixType>
typename MatrixPower<MatrixType>::RealScalar MatrixPower<MatrixType>::split(RealScalar x, RealScalar* intpart) void MatrixPower<MatrixType>::split(RealScalar& p, RealScalar& intpart)
{ {
*intpart = std::floor(x); intpart = std::floor(p);
RealScalar res = x - *intpart; p -= intpart;
if (!m_conditionNumber && res) if (!m_conditionNumber && p)
initialize(); initialize();
if (res > RealScalar(0.5) && res > (1-res) * std::pow(m_conditionNumber, res)) { if (p > RealScalar(0.5) && p > (1-p) * std::pow(m_conditionNumber, p)) {
--res; --p;
++*intpart; ++intpart;
} }
return res;
} }
template<typename MatrixType> template<typename MatrixType>