What data stucture should I use for BigInt class
Posted
by
user1086004
on Stack Overflow
See other posts from Stack Overflow
or by user1086004
Published on 2012-03-30T12:06:47Z
Indexed on
2012/03/30
17:30 UTC
Read the original article
Hit count: 193
I would like to implement a BigInt class which will be able to handle really big numbers. I want only to add and multiply numbers, however the class should also handle negative numbers.
I wanted to represent the number as a string, but there is a big overhead with converting string to int and back for adding. I want to implement addition as on the high school, add corresponding order and if the result is bigger than 10, add the carry to next order.
Then I thought that it would be better to handle it as a array of unsigned long long int and keep the sign separated by bool. With this I'm afraid of size of the int, as C++ standard as far as I know guarantees only that int < float < double. Correct me if I'm wrong. So when I reach some number I should move in array forward and start adding number to the next array position.
Is there any data structure that is appropriate or better for this? Thanks in advance.
© Stack Overflow or respective owner