Eigen-Contrib  5.0.1-dev+master
 
Loading...
Searching...
No Matches
MPFRC++ Support module
#include <contrib/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.

MPFR C++ is not bundled with Eigen: install its mpreal.h separately. The test mpreal_support is built only if mpreal.h is found by cmake/FindMPREAL.cmake (searching $GMPDIR and INCLUDE_INSTALL_DIR, then the default paths), in addition to MPFR and GMP.

Here is an example:

#include <iostream>
#include <contrib/Eigen/MPRealSupport>
#include <Eigen/LU>
using namespace mpfr;
using namespace Eigen;
int main()
{
// set precision to 256 bits (double has only 53 bits)
mpreal::set_default_prec(256);
// Declare matrix and vector types with multi-precision scalar type
using MatrixXmp = Matrix<mpreal,Dynamic,Dynamic>;
using VectorXmp = Matrix<mpreal,Dynamic,1>;
MatrixXmp A = MatrixXmp::Random(100,100);
VectorXmp b = VectorXmp::Random(100);
// Solve Ax=b using LU
VectorXmp x = A.lu().solve(b);
std::cout << "relative error: " << (A*x - b).norm() / b.norm() << std::endl;
return 0;
}
Namespace containing all symbols from the Eigen library.