• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////
2 //  Copyright 2011 John Maddock. Distributed under the Boost
3 //  Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
5 
6 //[mpfr_eg
7 #include <boost/multiprecision/mpfr.hpp>
8 #include <boost/math/special_functions/gamma.hpp>
9 #include <iostream>
10 
main()11 int main()
12 {
13    using namespace boost::multiprecision;
14 
15    // Operations at variable precision and no numeric_limits support:
16    mpfr_float a = 2;
17    mpfr_float::default_precision(1000);
18    std::cout << mpfr_float::default_precision() << std::endl;
19    std::cout << sqrt(a) << std::endl; // print root-2
20 
21    // Operations at fixed precision and full numeric_limits support:
22    mpfr_float_100 b = 2;
23    std::cout << std::numeric_limits<mpfr_float_100>::digits << std::endl;
24    // We can use any C++ std lib function:
25    std::cout << log(b) << std::endl; // print log(2)
26    // We can also use any function from Boost.Math:
27    std::cout << boost::math::tgamma(b) << std::endl;
28    // These even work when the argument is an expression template:
29    std::cout << boost::math::tgamma(b * b) << std::endl;
30 
31    // Access the underlying data:
32    mpfr_t r;
33    mpfr_init(r);
34    mpfr_set(r, b.backend().data(), GMP_RNDN);
35    mpfr_clear(r);
36    return 0;
37 }
38 //]
39 
40 
41