How to define function with arbitrary precision (Eigen/MPRealSupport)

  c++, eigen, mpfr

How to define Matrix<mpreal, Dynamic, Dynamic> with typedef?

We usually put the defined type in a header file, but it needs mpreal::set_default_prec(256); and that’s the problem.

I am quite new to MPFR, so my apology if it seems easy.
So what is your idea?

#include <Eigen/LU>
#include <iostream>
#include <Eigen/Dense>
#include "mylibrary.hpp"
#include <unsupported/Eigen/MPRealSupport>

using namespace mpfr;
using namespace Eigen;

MatrixXmp hilbert_matrix(const int size)
    MatrixXmp A = MatrixXmp::Zero(size, size);
    for (int i = 1; i < size + 1; ++i)
        for (int j = 1; j < size + 1; ++j)
            A(i - 1, j - 1) = 1. / (i + j - 1.);

    return A;

int main()
    // set precision to 256 bits (double has only 53 bits)

    typedef Matrix<mpreal, Dynamic, Dynamic> MatrixXmp;
    typedef Matrix<mpreal, Dynamic, 1> VectorXmp;

    return 0;


‘MatrixXmp’ does not name a type

Source: Windows Questions C++