3

Possible Duplicate:
“BigInt” in C?

Hey there! I'm calculating the Fibonacci numbers in C up to 46 using an unsigned int, but I can't calculate F(47) because it's long. So, is there a way to get numbers bigger than 2^32 in C?
NB: I use a 32-bit processor.

Community
  • 1
  • 1
seriousdev
  • 7,519
  • 8
  • 45
  • 52

5 Answers5

11

(unsigned) long long, but it's also limited (to 2^64). If it's not enough, you need to look for a BigInt library.

GameZelda
  • 824
  • 1
  • 7
  • 13
2
#include <stdint.h>

uint64_t my64bit;
Dacav
  • 13,590
  • 11
  • 60
  • 87
1

You could try using 64-bit unsigned integers (check your C implementation for support), or simply use a BigNum package like GMP.

In the past, I've made BigNum libraries myself for various purposes but GMP blows my meagre efforts out of the water.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
1

I love the answer given by user R.. for this question here to operate on bigints. Of-course you have to implement your own add function if you want to scale it to very large numbers. It explains the steps very clearly.

Community
  • 1
  • 1
Praveen S
  • 10,355
  • 2
  • 43
  • 69
0

You should implement your own data type that is able to hold big numbers or use a library such as this one.

Hamid Nazari
  • 3,905
  • 2
  • 28
  • 31