Operation with long_numbers
OK, I couldn't find anything about this topic, so it's either that i'm not looking where I should, or i'm not looking for what i should. If there is such a topic on this forum, then the search tool sux :D.
Long doesn't stand for the numeric type LONG <aka 0-2^16-1>, but really long <aka many digits> numbers, which wouldn't fit in any numeric type. So these numbers are stored as arrays (1 dim: e.g. 1024 is stored in num: num[1]=1, num[2]=0, num[3]=2, num[4]=4).
My question is: does anyone have any idea about mathematical algorithms to use with such numbers?? (where to find info about that, or even already made)
Addition is easy: just add array elements and watch out for carry...
What about multiplication, or even more complex operations??
PS: yep, search tool not that reliable... found something on the 9th page of results...
Re: Operation with long_numbers
Re: Operation with long_numbers
Hi draqula,
If you want to study the algorithms, see Knuth's The Art of Computer Programming, Seminumerical Algorithms.
If you want an implementation, I prefer Crypto++. An implementation of Knuth can be found here.
For a tutorial on using the CryptoPP::Integer, see A Big Integer Package for Use in Visual Basic Written in Visual C++. The article is a COM wrapper, but the mathematical operations are the same.
Jeff
Re: Operation with long_numbers
In this case I guess "pencil-and-paper" algorithms would be enough.
Re: Operation with long_numbers
What do you mean by that??
Re: Operation with long_numbers
There is not much of reasoning with calculation on paper, just algorithms. Apart from that, division may be implemented using bisection, that is to divide x=a/b you search a solution to equation x*b-a=0, keeping track of lower and upper bounds [x1, x2] on x and shifting bounds to either [(x1+x2)/2, x2] or [x1, (x1+x2)/2]. To implement this you'll only need division by 2, which is quite straightforward.