0

I am currently working on a problem that calculates pi. The calculating part works fine but with my current data-type I can only calculate a certain amount of digits, before it stops storing them (~32?).

I am using a long double, but I want more digits, preferably a variable amount.

#include <iostream>
#include <math.h>
#include<bits/stdc++.h>
//variables
float sign = 1.0;
long double sum = 0.0;
float start = 3.0;
int iteration = 0.0;

int main() {

    std::cout << "How many iterations should be completed?" << std::endl;
    std::cin >> iteration;
//calculating part
    for (int j = 1; j < iteration; j++) {
        sum = sum + sign * 4.0 / ((2 * j) * (2 * j + 1.0) * (2 * j + 2.0));
        sign *= -1.0;
    }
//output     
    std::cout << std::fixed << std::setprecision(1000) << sum + start << std::endl;

    return 0;
}

I get what I expect, but I did not find a data-type, that stores even more. Do I have to write one myself?

0 Answers0