I'm using Bloodshed DevCpp version 4.9.9.2 (version five beta) as my compiler and IDE, and I am trying to compute pi truncated to the first 15 decimal places, only there is a problem. I am using a while loop for my computation, and I've figured out that in order to get all decimal places right I need a loop that repeates over 1 billion times to recieve one hundred percent accuracy. However, it will not compile for some reason. The message the compiler displayes is something like "intager constant to large for 'long' type". WHAT? Long is 32 bits, and long long is 64 bits, and I am computing with a 64 bit long, but it says I'm computing with a long. Here is the code :
#include <iostream>
#include <limits>
using namespace std;
int main()
{
double pi = 4.0/1.0;
unsigned long long int divide = 3;
double calculate = 4.0 / divide;
unsigned long long int loops = 0;
while(loops != 1000000000000) //Line that produces a compile error
{
loops++;
if(loops % 2 != 0)
{
pi = pi  calculate;
divide = divide + 2;
calculate = 4.0 / divide;
}
if(loops % 2 == 0)
{
pi = pi + calculate;
divide = divide + 2;
calculate = 4.0 / divide;
}
}
cout.precision(15);
cout << pi;
cin.get();
return 0;
}
I realize that it may be less than that to produce accuracy that is desirable, but it is not that that bugs me, it is the fact that the compiler won't let me compute with 64 bit intagers unless I use predefined limits in the <limits> header file. I am concerned about this now because it may prevent me from doing flexible computations in future programs, but right now it is limited. Can someone tell me why this is? And how to fix it perhaps?
