By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

Help with 64 bit intagers

P: 23
I'm using Bloodshed Dev-Cpp 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?
Jun 16 '07 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
Are you using 64-bit Windows??

If you are, the long long and the long are 32 bits.

Probably, you need to use _int64.

If you are not using Windows, have yo done a sizeof( long long) to see how big it is?
Jun 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.