aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/examples/class_Cast.cpp
blob: 456466d1f4ce89f661c4c5ef17528253ae2e1957 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#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;
}