MPFRC++ Support module
1 #include <Eigen/MPRealSupport>

This module provides support for multi precision floating point numbers via the MPFR C++ library which itself is built upon MPFR/GMP.

Warning
MPFR C++ is licensed under the GPL.

You can find a copy of MPFR C++ that is known to be compatible in the unsupported/test/mpreal folder.

Here is an example:

1 #include <iostream>
2 #include <Eigen/MPRealSupport>
3 #include <Eigen/LU>
4 using namespace mpfr;
5 using namespace Eigen;
6 int main()
7 {
8  // set precision to 256 bits (double has only 53 bits)
9  mpreal::set_default_prec(256);
10  // Declare matrix and vector types with multi-precision scalar type
11  typedef Matrix<mpreal,Dynamic,Dynamic> MatrixXmp;
12  typedef Matrix<mpreal,Dynamic,1> VectorXmp;
13 
14  MatrixXmp A = MatrixXmp::Random(100,100);
15  VectorXmp b = VectorXmp::Random(100);
16 
17  // Solve Ax=b using LU
18  VectorXmp x = A.lu().solve(b);
19  std::cout << "relative error: " << (A*x - b).norm() / b.norm() << std::endl;
20  return 0;
21 }