0

My C++ programme may create a value until 10^16 during the run time, I tried to use "long long int" for it but it didn't work. Which data type correspond to 10^16?

Thanks;

8
  • 5
    Can you be more specific than "it didn't work" please? Commented Mar 23, 2013 at 18:45
  • there is no answer in my programme for 6 minutes, when i finished my programme i saw overflow error.
    – eponymous
    Commented Mar 23, 2013 at 18:54
  • @Selen That sounds more like a stack overflow than an integer overflow. What makes you think the 10^16 value is the problem? Commented Mar 23, 2013 at 18:55
  • 2
    Clearly your problem then is not that long long int does not hold 10^16. It is somewhere in the logic of your program, which we can't see. So this question is answered. You should accept an answer and ask a new question about your code and what is wrong with it. Commented Mar 23, 2013 at 19:28
  • 1
    If you are multiplying this sized long long values, they will overflow. Commented Mar 23, 2013 at 20:25

4 Answers 4

6

The minimum guaranteed maximum of long long int is 2^63 - 1, which is approximately 10^19. It should be fine. To be sure, use the std::int_least64_t type from <cstdint>. It is guaranteed to have at least 64 bits.

1

less than 64bit so.. long long should be good..

2
  • This should probably be a comment unless you can expand a bit on it.
    – Mysticial
    Commented Mar 23, 2013 at 19:03
  • i tried long long but it didnt work i think that problem is about compiler, thanks for your answer.
    – eponymous
    Commented Mar 23, 2013 at 19:36
1

Try int64_t. That should be long enough. But be sure to enter an integer literal:

int64_t n = 10000000000000000;

If you say 1E16, that's a double literal, and the conversion to integer may produce unexpected results.

2
  • 2
    10000000000000000LL <- the suffix might be required for some compilers.
    – s3rius
    Commented Mar 23, 2013 at 19:10
  • Unless you're running your gcc in pre-C99 mode, which seems you are by default, (or if it's simply some C89/90 compiler) and the compiler truncates what would've been a normal long long constant in C99 to the longest integer type supported by C89, which is long (or unsigned long). Surprise. Commented Mar 24, 2013 at 8:51
-2

Unsigned long long Int works up-to 10^18!

1
  • Welcome to Stack Overflow! The question is not on-topic for Stack Overflow as defined in the help center. Please don't answer such questions; instead, you should flag them for attention and they will be closed or migrated appropriately. Commented Oct 19, 2016 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.