Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Using With MPFR / GMP - a High-Precision Floating-Point Library
PrevUpHomeNext

The special functions and tools in this library can be used with MPFR (an arbitrary precision number type based on the GMP library), via the bindings in boost/math/bindings/mpfr.hpp.

In order to use these binings you will need to have installed MPFR plus it's dependency the GMP library and the C++ wrapper for MPFR known as gmpfrxx (or mpfr_class).

Unfortunately mpfr_class doesn't quite satisfy our conceptual requirements, so there is a very thin set of additional interfaces and some helper traits defined in boost/math/bindings/mpfr.hpp that you should use in place of including 'gmpfrxx.h' directly. The existing mpfr_class is then usable unchanged once this header is included, so it's performance-enhancing expression templates are preserved and fully supported by this library:

#include <boost/math/bindings/mpfr.hpp>
#include <boost/math/special_functions/gamma.hpp>

int main()
{
   mpfr_class::set_dprec(500); // 500 bit precision
   //
   // Note that the argument to tgamma is an expression template,
   // that's just fine here:
   //
   mpfr_class v = boost::math::tgamma(sqrt(mpfr_class(2)));
   std::cout << std::setprecision(50) << v << std::endl;
}

For those functions that are based upon the Lanczos approximation, the bindings defines a series of approximations with up to 61 terms and accuracy up to approximately 3e-113. This therefore sets the upper limit for accuracy to the majority of functions defined this library when used with mpfr_class.

There is a concept checking test program for mpfr support here.


PrevUpHomeNext