Boost logo

Boost Users :

Subject: Re: [Boost-users] MPFR in Boost 1.45.0
From: Novak Elliott (n.s.j.elliott_at_[hidden])
Date: 2011-02-05 09:10:46


Oops, a bit of a rookie error. Thanks John.

So to summarise for those that search the archives:

As per "Link Your Program to a Boost program" (
http://www.boost.org/doc/libs/1_45_0/more/getting_started/unix-variants.html#link-your-program-to-a-boost-library),
and other basic gcc/g++ documentation, the example "Using with MPR / GMP - a
High-Precision Floating-Point Library" (
http://www.boost.org/doc/libs/1_45_0/libs/math/doc/sf_and_dist/html/math_toolkit/using_udt/use_mpfr.html
):

boost_mpfr_example.cpp:

#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;
}

Should be compiled and linked with the following command:
g++ -I/path/to/boost_1_45_0 boost_mpfr_example.cpp -o boost_mpfr_example
-lgmpfrxx -lmpfr -lgmpxx -lgmp

On Ubuntu 10.10 the following packages (or source) are needed:
- MPFR 3.0.0-2 (ubuntu packages: libmpfr-dev, libmpfr4),
- gmp 4.3.2 (libgmp3-dev, libgmp3c2, libgmpxx4ldbl),
- gmpfrxx (http://math.berkeley.edu/~wilken/code/gmpfrxx/).

Running ./boost_mpfr_example should give:
8.8658142871925912508091761239199431116828551763805e-1

cheers,
Novak.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net