1 year ago

#266138

test-img

theneon

How to increase double's precision in c++?

I try to calculating one series, using formula (2^n + 1) / (3^n - 1);

In the code below you can see how I do that:

#include <math.h> 
#include <iomanip>

using namespace std;

// 3.0856067145849229494715404431559591102995909750461578369140625 - {61 digits after dot} it's my record

int main() {
    int n = 1;
    char newl = '\n';
    long double res = (pow(2.0, n) + 1) / (pow(3.0, n) - 1);
    cout << fixed << setprecision(500) << res << newl;
    while (n < 10000) {
        n++;
        res += (pow(2.0, n) + 1) / (pow(3.0, n) - 1);
        cout << res << newl;
    }
    return 0;
}

And I want to improve my result, calcuting at least 100 digits after dot. Is that possible? If answer can be founded, give a way to solving this task, please. Sorry in advance for my bad English if I mistaked somewhere, thanks for all answers which will help and good luck to everyone.

c++

double

pow

0 Answers

Your Answer

Accepted video resources