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,300
  • 8
  • 42
  • 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
  • 794
  • 1
  • 6
  • 12
2
#include <stdint.h>

uint64_t my64bit;
Dacav
  • 12,630
  • 9
  • 57
  • 84
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
  • 814,905
  • 225
  • 1,535
  • 1,899
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,257
  • 2
  • 41
  • 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,771
  • 2
  • 27
  • 30