I've been thinking some time about programming a collection of functions, sort of like a library (or perhaps even make it a class), to handle very large integer numbers.
My approach on this was to store the numbers as a string and then create the functions to handle strings and return a string.
I managed to write functions for Addition, Substraction, Multiplication, Dividation and Modulus, and a rough version of a Power function.
However, as I look at the code I cannot possibly believe that it'll work fast at all. Handling strings, making dozens of copies all the time, using Mid$ and string pasting operations etc can't be good.
I am wondering if anyone has an idea about how to create functions to handle very large integer numbers with some speed. Mostly talking about multiplication here, which I believe to be the slowest (I'm not even going to mention the Power function...).
A more detailed description of what I do when adding two numbers is this: I take a string number, I chop it into pieces (fixed length) and then do the operation on each block seperately: convert the two blocks you want to add together to a Long, let VB do the addition and remember the remainder (the part of the number that does not fit in the fixed length block). Then do the next two blocks, accounting for the remainder you had left from the previous two blocks.
The chopping the strings into blocks alone is a time-consuming process (for practical reasons I also reverse the order of the blocks from what is normal, eg last block comes first, first block becomes last).
Any ideas and thoughts would be much appreciated.
0 · ·