3 <meta http-equiv=
"Content-Type" content=
"text/html; charset=US-ASCII">
4 <title>Using With MPFR or GMP - High-Precision Floating-Point Library
</title>
5 <link rel=
"stylesheet" href=
"../../math.css" type=
"text/css">
6 <meta name=
"generator" content=
"DocBook XSL Stylesheets V1.77.1">
7 <link rel=
"home" href=
"../../index.html" title=
"Math Toolkit 2.5.1">
8 <link rel=
"up" href=
"../high_precision.html" title=
"Using Boost.Math with High-Precision Floating-Point Libraries">
9 <link rel=
"prev" href=
"float128.html" title=
"Using with GCC's __float128 datatype">
10 <link rel=
"next" href=
"e_float.html" title=
"Using e_float Library">
12 <body bgcolor=
"white" text=
"black" link=
"#0000FF" vlink=
"#840084" alink=
"#0000FF">
13 <table cellpadding=
"2" width=
"100%"><tr>
14 <td valign=
"top"><img alt=
"Boost C++ Libraries" width=
"277" height=
"86" src=
"../../../../../../boost.png"></td>
15 <td align=
"center"><a href=
"../../../../../../index.html">Home
</a></td>
16 <td align=
"center"><a href=
"../../../../../../libs/libraries.htm">Libraries
</a></td>
17 <td align=
"center"><a href=
"http://www.boost.org/users/people.html">People
</a></td>
18 <td align=
"center"><a href=
"http://www.boost.org/users/faq.html">FAQ
</a></td>
19 <td align=
"center"><a href=
"../../../../../../more/index.htm">More
</a></td>
22 <div class=
"spirit-nav">
23 <a accesskey=
"p" href=
"float128.html"><img src=
"../../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../high_precision.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=
"e_float.html"><img src=
"../../../../../../doc/src/images/next.png" alt=
"Next"></a>
26 <div class=
"titlepage"><div><div><h3 class=
"title">
27 <a name=
"math_toolkit.high_precision.use_mpfr"></a><a class=
"link" href=
"use_mpfr.html" title=
"Using With MPFR or GMP - High-Precision Floating-Point Library">Using With MPFR
28 or GMP - High-Precision Floating-Point Library
</a>
29 </h3></div></div></div>
31 The special functions and tools in this library can be used with
<a href=
"http://www.mpfr.org" target=
"_top">MPFR
</a>
32 (an arbitrary precision number type based on the
<a href=
"http://gmplib.org/" target=
"_top">GNU
33 Multiple Precision Arithmetic Library
</a>), either via the bindings in
34 <a href=
"../../../../../../boost/math/bindings/mpfr.hpp" target=
"_top">boost/math/bindings/mpfr.hpp
</a>,
35 or via
<a href=
"../../../../../../boost/math/bindings/mpfr.hpp" target=
"_top">boost/math/bindings/mpreal.hpp
</a>.
38 <span class=
"bold"><strong>New projects are recommended to use
<a href=
"../../../../../../libs/multiprecision/doc/html/index.html" target=
"_top">Boost.Multiprecision
</a>
39 with GMP/MPFR backend instead.
</strong></span>
42 In order to use these bindings you will need to have installed
<a href=
"http://www.mpfr.org" target=
"_top">MPFR
</a>
43 plus its dependency the
<a href=
"http://gmplib.org" target=
"_top">GMP library
</a>.
44 You will also need one of the two supported C++ wrappers for MPFR:
<a href=
"http://math.berkeley.edu/~wilken/code/gmpfrxx/" target=
"_top">gmpfrxx (or mpfr_class)
</a>,
45 or
<a href=
"http://www.holoborodko.com/pavel/mpfr/" target=
"_top">mpfr-C++ (mpreal)
</a>.
48 Unfortunately neither
<code class=
"computeroutput"><span class=
"identifier">mpfr_class
</span></code>
49 nor
<code class=
"computeroutput"><span class=
"identifier">mpreal
</span></code> quite satisfy
50 our conceptual requirements, so there is a very thin set of additional interfaces
51 and some helper traits defined in
<a href=
"../../../../../../boost/math/bindings/mpfr.hpp" target=
"_top">boost/math/bindings/mpfr.hpp
</a>
52 and
<a href=
"../../../../../../boost/math/bindings/mpreal.hpp" target=
"_top">boost/math/bindings/mpreal.hpp
</a>
53 that you should use in place of including 'gmpfrxx.h' or 'mpreal.h' directly.
54 The classes
<code class=
"computeroutput"><span class=
"identifier">mpfr_class
</span></code> or
55 <code class=
"computeroutput"><span class=
"identifier">mpreal
</span></code> are then usable unchanged
56 once this header is included, so for example
<code class=
"computeroutput"><span class=
"identifier">mpfr_class
</span></code>'s
57 performance-enhancing expression templates are preserved and fully supported
60 <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>
61 <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>
63 <span class=
"keyword">int
</span> <span class=
"identifier">main
</span><span class=
"special">()
</span>
64 <span class=
"special">{
</span>
65 <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>
66 <span class=
"comment">//
</span>
67 <span class=
"comment">// Note that the argument to tgamma is
</span>
68 <span class=
"comment">// an expression template - that's just fine here.
</span>
69 <span class=
"comment">//
</span>
70 <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>
71 <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>
72 <span class=
"special">}
</span>
75 Alternatively use with
<code class=
"computeroutput"><span class=
"identifier">mpreal
</span></code>
78 <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">mpreal
</span><span class=
"special">.
</span><span class=
"identifier">hpp
</span><span class=
"special">></span>
79 <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>
81 <span class=
"keyword">int
</span> <span class=
"identifier">main
</span><span class=
"special">()
</span>
82 <span class=
"special">{
</span>
83 <span class=
"identifier">mpfr
</span><span class=
"special">::
</span><span class=
"identifier">mpreal
</span><span class=
"special">::
</span><span class=
"identifier">set_precision
</span><span class=
"special">(
</span><span class=
"number">500</span><span class=
"special">);
</span> <span class=
"comment">//
500 bit precision
</span>
84 <span class=
"identifier">mpfr
</span><span class=
"special">::
</span><span class=
"identifier">mpreal
</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
</span><span class=
"special">::
</span><span class=
"identifier">mpreal
</span><span class=
"special">(
</span><span class=
"number">2</span><span class=
"special">)));
</span>
85 <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>
86 <span class=
"special">}
</span>
89 For those functions that are based upon the
<a class=
"link" href=
"../lanczos.html" title=
"The Lanczos Approximation">Lanczos
90 approximation
</a>, the bindings defines a series of approximations with
91 up to
61 terms and accuracy up to approximately
3e-113. This therefore sets
92 the upper limit for accuracy to the majority of functions defined this library
93 when used with either
<code class=
"computeroutput"><span class=
"identifier">mpfr_class
</span></code>
94 or
<code class=
"computeroutput"><span class=
"identifier">mpreal
</span></code>.
97 There is a concept checking test program for mpfr support
<a href=
"../../../../../../libs/math/test/mpfr_concept_check.cpp" target=
"_top">here
</a>
98 and
<a href=
"../../../../../../libs/math/test/mpreal_concept_check.cpp" target=
"_top">here
</a>.
101 <table xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width=
"100%"><tr>
102 <td align=
"left"></td>
103 <td align=
"right"><div class=
"copyright-footer">Copyright
© 2006-
2010,
2012-
2014 Nikhar Agrawal,
104 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
105 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R
åde, Gautam Sewani,
106 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang
<p>
107 Distributed under the Boost Software License, Version
1.0. (See accompanying
108 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>)
113 <div class=
"spirit-nav">
114 <a accesskey=
"p" href=
"float128.html"><img src=
"../../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../high_precision.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=
"e_float.html"><img src=
"../../../../../../doc/src/images/next.png" alt=
"Next"></a>