eigen/doc/examples/class_Cast.cpp
Benoit Jacob afc64f3332 a lot of renaming
internal classes: AaBb -> ei_aa_bb
IntAtRunTimeIfDynamic -> ei_int_if_dynamic
unify UNROLLING_LIMIT (there was no reason to have operator= use
a higher limit)
etc...
2008-03-13 09:33:26 +00:00

28 lines
652 B
C++

#include <Eigen/Core>
USING_PART_OF_NAMESPACE_EIGEN
using namespace std;
template<typename Derived>
const Eigen::CwiseUnaryOp<
Eigen::ei_scalar_cast_op<
typename Eigen::ei_traits<typename Derived::Scalar>::FloatingPoint
>, Derived
>
castToFloatingPoint(const MatrixBase<Derived>& m)
{
return m.template cast<
typename Eigen::ei_traits<
typename Derived::Scalar
>::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;
}