eigen/doc/examples/class_Cast.cpp
Benoit Jacob 01572b9f54 big change: MatrixBase only takes one template parameter "Derived", the
template parameter "Scalar" is removed. This is achieved by introducting a
template <typename Derived> struct Scalar to achieve a forward-declaration of
the Scalar typedefs.
2008-03-10 17:23:11 +00:00

26 lines
663 B
C++

#include <Eigen/Core>
USING_PART_OF_NAMESPACE_EIGEN
using namespace std;
template<typename Derived>
const Eigen::CwiseUnaryOp<
Eigen::ScalarCastOp<
typename Eigen::NumTraits< typename Eigen::Scalar<Derived>::Type >::FloatingPoint
>, Derived
>
castToFloatingPoint(const MatrixBase<Derived>& m)
{
return m.template cast<typename Eigen::NumTraits<
typename Eigen::Scalar<Derived>::Type>::FloatingPoint
>();
}
int main(int, char**)
{
Matrix2i m = Matrix2i::random();
cout << "Here's the matrix m. It has coefficients of type int."
<< endl << m << endl;
cout << "Here's m/20:" << endl << castToFloatingPoint(m)/20 << endl;
return 0;
}