1. long long's what gives?

Hi,

I'm doing something that needs to use a 64 bit integer in c++. I assume this would be the long long. My question is when you use any of the standard operators, *,/,%,etc. you get zero if your integer is bigger than INT_MAX. How do I multiply and divide these things? Is this the 64 bit int I should be using? Any help is greatly appreciated.

2. >> I assume this would be the long long.

Well don't. A long long is not a standard type, and even if it was there likely wouldn't be a guarantee on the size.

>> My question is when you use any of the standard operators, *,/,%,etc. you get zero if your integer is bigger than INT_MAX.

Post a compilable example of the problem.

3. Are you sure?
The reason I ask is that until very recently, printf() in Windows used a non-standard operator of %I64d, instead of %lld. (I believe that %lld was introduced with Vista, but on this point I could be wrong. It was definitely absent in 98.) If you're printing out the number using the wrong modifiers, you'll certainly get the wrong answer, and possibly corrupt your stack.

That said, something like:
Code:
```long long n = 5000000000LL;
n /= 2;```
should do the right thing. Post a minimal problematic example if you have troubles.

4. Code:
`long long int a = 12345LL;`
Add the correct suffix code to your constants to make them the right type to begin with.

5. Originally Posted by Salem
Code:
`long long int a = 12345LL;`
Add the correct suffix code to your constants to make them the right type to begin with.
I'm not using constants. I have something like:

Code:
```long long totalSize = (long long)(pow(2,inputParameterPassedFromConsole));
avgSize = totalSize/numProcessors;
I am also going to be doing this which will GENERATE integers bigger than INT_MAX through multiplication and division (and other stuff) of input variables.

6. >> I'm not using constants. I have something like:

Well is pow giving you the correct result?

7. I am also going to be doing this which will GENERATE integers bigger than INT_MAX through multiplication and division (and other stuff) of input variables.
That's fine. INT_MAX has little to do with long longs. You will be fine as long as you don't overflow a long long.

8. > long long totalSize = (long long)(pow(2,inputParameterPassedFromConsole));
Using pow() to calculate powers of 2 just SUCKS.

1. It's horribly inefficient.
2. doubles only have about 50 or so bits of precision, so for very large numbers you just get inaccurate results.

The quick way?
Code:
`long long totalSize = 2LL << inputParameterPassedFromConsole;`

9. >> The quick way?

Excellent idea! But the calculation is slightly off - should be:

1LL << inputParameterPassedFromConsole

10. Originally Posted by maverick_starst
long long's what gives?
please note that the apostrophe is NEVER used in the english language to modify a noun to plural form. it seems like english is your first language, otherwise I would say nothing about it. the apostrophe is used to join words into contractions and to modify a noun to possessive form. I see misuse of the apostrophe far too often, and it irritates me to see people do it when I know for a fact they were taught the right way in school. when I was in school, we learned in 3rd grade how to use the apostrophe, and how to construct a plural noun. since most people frequenting this board are at least chronologically older than that, I would expect that most should know this.

11. Originally Posted by Elkvis
please note that the apostrophe is NEVER used in the english language to modify a noun to plural form. it seems like english is your first language, otherwise I would say nothing about it. the apostrophe is used to join words into contractions and to modify a noun to possessive form. I see misuse of the apostrophe far too often, and it irritates me to see people do it when I know for a fact they were taught the right way in school. when I was in school, we learned in 3rd grade how to use the apostrophe, and how to construct a plural noun. since most people frequenting this board are at least chronologically older than that, I would expect that most should know this.
Also, note that both proper nouns (eg: English) and the first word of a sentence should be capitalized.

12. please note that the apostrophe is NEVER used in the english language to modify a noun to plural form. it seems like english is your first language, otherwise I would say nothing about it. the apostrophe is used to join words into contractions and to modify a noun to possessive form. I see misuse of the apostrophe far too often, and it irritates me to see people do it when I know for a fact they were taught the right way in school. when I was in school, we learned in 3rd grade how to use the apostrophe, and how to construct a plural noun. since most people frequenting this board are at least chronologically older than that, I would expect that most should know this.
Apostrophes ARE used to make plural forms.
Apostrophe - The OWL at Purdue
Apostrophes are used to form plurals of letters that appear in lowercase; here the rule appears to be more typographical than grammatical, e.g. "three ps" versus "three p's." To form the plural of a lowercase letter, place 's after the letter.
There is no need for apostrophes indicating a plural on capitalized letters, numbers, and symbols (though keep in mind that some editors, teachers, and professors still prefer them).
Yes, many people "mis-use" it for other things, but I think it's more of a historical and conventional thing, and they know perfectly well that apostrophes are usually not used to pluralize.

When I see a 's for pluralization, I take it as a clarification that it is for pluralization. It may not be so clear otherwise with abbreviations for example. If you have MP3s, and you didn't previously know what MP3 means, you could be misled to think "s" is part of the abbreviation.

I'm not sure if my interpretation is the common interpretation, since English is not my native language.

13. Originally Posted by Elkvis
please note that the apostrophe is NEVER used in the english language to modify a noun to plural form. it seems like english is your first language, otherwise I would say nothing about it. the apostrophe is used to join words into contractions and to modify a noun to possessive form. I see misuse of the apostrophe far too often, and it irritates me to see people do it when I know for a fact they were taught the right way in school. when I was in school, we learned in 3rd grade how to use the apostrophe, and how to construct a plural noun. since most people frequenting this board are at least chronologically older than that, I would expect that most should know this.
I also wrote the title in like half a second and didn't bother reviewing. However, I do find grammar nazi's (mwahahaha) to be incredibly mis-guided individuals. Feynman has some really amusing anecdotes about how silly such people are. Also, no, grammar isn't explicitly taught in schools any more; (ooh a semi-colon) that time is now used for actually reading books. Take it up with the school board but, to me, lamenting the "death of the english language" is as silly as lamenting the "death of old norse". It never ceases to amaze me how full of themselves grammar nazis get. Especially in a bloody internet forum. You really think you're getting a fix on peoples education? I don't know about you but I frequently write homonyms of what I meant to type as well as make punctuation and spelling errors when typing, and it's really not worth the time to fix them. I bet you find words like "dunno" or the addition of "ness", "y" or "like" to the end of words where it is not normally added to be a corruption of the english language. Anywho, (mwahaha) if finding grammar mistake gets you hot I guess a c++ forum is a good place to troll.

14. Anyways, thanks for the help everybody. I seem to have it working now but I'm not entirely sure where the problem was. I just went through it all and made sure everything was explicitely cast (like (long long)(x)=(long long)(y)*int(z) and it seems to give the correct result now.

15. is that for real!!
i googled it and there are more like this (as far as i could remember)
long long int

and other four ones :S !!

do they have useful uses ? what are they ?