SHARE
TWEET

Untitled

a guest Jul 12th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<boost/multiprecision/mpfr.hpp>
  2. #include<iostream>
  3.  
  4. using namespace boost::multiprecision;
  5. using namespace std;
  6.  
  7. constexpr unsigned DIGIT = 100'000'001;
  8. using my_mpfr_float = number<mpfr_float_backend<DIGIT>>;
  9.  
  10. my_mpfr_float operator"" _big(unsigned long long n) {
  11.     return my_mpfr_float(n);
  12. }
  13.  
  14. int main() {
  15.     my_mpfr_float a = 1_big;
  16.     my_mpfr_float b = 1_big / sqrt(2_big);
  17.     my_mpfr_float t = 1_big / 4_big;
  18.     my_mpfr_float p = 1_big;
  19.  
  20.     for (my_mpfr_float n = 0_big, lim = log2(DIGIT); n < lim; n++) {
  21.         my_mpfr_float pa = a, pb = b, pt = t, pp = p;
  22.         a = (pa + pb) / 2_big;
  23.         b = sqrt(pa * pb);
  24.         t = pt - pp * pow(pa - a, 2_big);
  25.         p = 2_big * pp;
  26.     }
  27.  
  28.     cout << setprecision(DIGIT) << pow(a + b, 2_big) / (4_big * t) << endl;
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top