Integers of unlimited size?
Asked Answered
F

2

7

In Python, I can write a program to calculate integers of unlimited size. Just the other day I did the one millionth fibonacci number, and it was so large It was unable to fit in the console. If this is possible to do in Python, which to my understanding was written in C, how could one do the same in C++? It has to be possible, otherwise I don't see how it could be done in Python. I also believe there is something similar in Java/C# called a Biginteger, but I couldn't find anything saying how it could be implemented in C++.

Funk answered 29/9, 2012 at 1:34 Comment(1)
Have a look at GMP.Blackwood
Z
13

Anything is possible in C/C++. You could write you own class called bigInteger and use an array to represent the number, but the best way is to use an already written library for working with big numbers, because those are very well optimized and a huge part of them is written in asm for extra speed. Here are a few examples:

Zia answered 29/9, 2012 at 1:40 Comment(2)
Thanks, I'll definitely look into it.Funk
class cBigNumber seems better than GMP, but I could not compile it.Honeysweet
J
6

Wikipedia lists a number of libraries you can use. Those that are denoted as C libraries can also be used in C++. C++ does not have a built-in bigint type.

As this reference shows, it's generally a good idea to google, check wikipedia and not the least, check the FAQ, before asking.

However, in this case, inexplicably, it seems that the FAQ does not provide an answer.

Jato answered 29/9, 2012 at 1:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.