Hi I was running through a recursive code And I realized on my personal computer, running the default Visual Studio debugger I can only fit 6776 times when using the run without debugging option before I get a Stack Overflow Error. When using the debugger I was able to get it to 6781. On cpp.sh I was able to get too 900 million.I am suspecting caching but it still does not explain everything. Since it is more accurate than onlinegdb by a significant margin which only goes to 205000. My computer is significantly less capable than the server cpp.sh uses, but not 132,723 times less. What software and hardware trickery is being used and how to make it consistent?
I am running Windows 10 Version 1903 using an Intel N3350 with 4GB Ram.
int main()
{
long double Answer = 0;
Answer = 3 + (Solver(2, 1, UserInput, 0));
}
double Solver(int counter, int group, int stop, long double partialanswer)
{
long double Counter = counter;
if (Counter >= stop)
{
return partialanswer;
}
if (group % 2 != 0)
{
partialanswer = partialanswer + (4 / ((Counter) * (Counter + 1) * (Counter + 2)));
}
else
{
partialanswer = partialanswer - (4 / ((Counter) * (Counter + 1) * (Counter + 2)));
}
Solver((counter + 2), (group+1), stop, partialanswer);
}
Note 3 Here is the full code if you need it.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double Solver(int counter, int group, int stop, long double partialanswer)
{
long double Counter = counter;
if (Counter >= stop)
{
return partialanswer;
}
//partialanswer = round(partialanswer * pow(2, 54)) / pow(2, 54);
if (group % 2 != 0)
{
partialanswer = partialanswer + (4 / ((Counter) * (Counter + 1) * (Counter + 2)));
}
else
{
partialanswer = partialanswer - (4 / ((Counter) * (Counter + 1) * (Counter + 2)));
}
Solver((counter + 2), (group+1), stop, partialanswer);
}
int main()
{
int UserInput;
long double Answer = 0;
cin >> UserInput;
Answer = 3 + (Solver(2, 1, UserInput, 0));
cout << "PI = " << setprecision(18) << Answer << endl;
cout << "reference Pi is equal to 3.1415926535897932384626433832795028841971 " << endl;
cout << " The Difference is equal to " <<fixed << setprecision(30) << abs(Answer - 3.1415926535897932384626433832795028841971) << endl;
}
Subtraction Code
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
long double UserInput1;
long double UserInput2;
cin >> UserInput1;
cin >> UserInput2;
cout << fixed << setprecision(32) << (UserInput1 - UserInput2);
}
[cached 100000000 before crash][6]
cached 900000000 after crash cached 100000000 after crash