<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <title>Using With MPFR / GMP - a High-Precision Floating-Point Library</title> <link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.74.0"> <link rel="home" href="../../index.html" title="Math Toolkit"> <link rel="up" href="../using_udt.html" title="Use with User-Defined Floating-Point Types"> <link rel="prev" href="use_ntl.html" title="Using With NTL - a High-Precision Floating-Point Library"> <link rel="next" href="concepts.html" title="Conceptual Requirements for Real Number Types"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <table cellpadding="2" width="100%"><tr> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> <td align="center"><a href="../../../../../../../index.html">Home</a></td> <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> <td align="center"><a href="../../../../../../../more/index.htm">More</a></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="use_ntl.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../using_udt.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="concepts.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> </div> <div class="section" lang="en"> <div class="titlepage"><div><div><h3 class="title"> <a name="math_toolkit.using_udt.use_mpfr"></a><a class="link" href="use_mpfr.html" title="Using With MPFR / GMP - a High-Precision Floating-Point Library"> Using With MPFR / GMP - a High-Precision Floating-Point Library</a> </h3></div></div></div> <p> The special functions and tools in this library can be used with <a href="http://www.mpfr.org" target="_top">MPFR (an arbitrary precision number type based on the GMP library)</a>, via the bindings in <a href="../../../../../../../boost/math/bindings/mpfr.hpp" target="_top">boost/math/bindings/mpfr.hpp</a>. </p> <p> In order to use these binings you will need to have installed <a href="http://www.mpfr.org" target="_top">MPFR</a> plus it's dependency the <a href="http://gmplib.org" target="_top">GMP library</a> and the C++ wrapper for MPFR known as <a href="http://math.berkeley.edu/~wilken/code/gmpfrxx/" target="_top">gmpfrxx (or mpfr_class)</a>. </p> <p> Unfortunately <code class="computeroutput"><span class="identifier">mpfr_class</span></code> doesn't quite satisfy our conceptual requirements, so there is a very thin set of additional interfaces and some helper traits defined in <a href="../../../../../../../boost/math/bindings/mpfr.hpp" target="_top">boost/math/bindings/mpfr.hpp</a> 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: </p> <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">bindings</span><span class="special">/</span><span class="identifier">mpfr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> <span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">special_functions</span><span class="special">/</span><span class="identifier">gamma</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> <span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> <span class="special">{</span> <span class="identifier">mpfr_class</span><span class="special">::</span><span class="identifier">set_dprec</span><span class="special">(</span><span class="number">500</span><span class="special">);</span> <span class="comment">// 500 bit precision </span> <span class="comment">// </span> <span class="comment">// Note that the argument to tgamma is an expression template, </span> <span class="comment">// that's just fine here: </span> <span class="comment">// </span> <span class="identifier">mpfr_class</span> <span class="identifier">v</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">mpfr_class</span><span class="special">(</span><span class="number">2</span><span class="special">)));</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="number">50</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">v</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span> </pre> <p> For those functions that are based upon the <a class="link" href="../backgrounders/lanczos.html" title="The Lanczos Approximation">Lanczos approximation</a>, 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 <code class="computeroutput"><span class="identifier">mpfr_class</span></code>. </p> <p> There is a concept checking test program for mpfr support <a href="../../../../../../../libs/math/test/mpfr_concept_check.cpp" target="_top">here</a>. </p> </div> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <td align="left"></td> <td align="right"><div class="copyright-footer">Copyright © 2006 , 2007, 2008, 2009 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno Lalande, Johan Råde, Gautam Sewani and Thijs van den Berg<p> Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) </p> </div></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="use_ntl.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../using_udt.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="concepts.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> </div> </body> </html>