Handling extremely large numbers in a language which can't?

Posted by Mallow on Programmers See other posts from Programmers or by Mallow
Published on 2012-01-20T20:46:41Z Indexed on 2012/06/09 22:46 UTC
Read the original article Hit count: 312

Filed under:
|
|

I'm trying to think about how I would go about doing calculations on extremely large numbers (to infinitum - intergers no floats) if the language construct is incapable of handling numbers larger than a certain value.

I am sure I am not the first nor the last to ask this question but the search terms I am using aren't giving me an algorithm to handle those situations. Rather most suggestions offer a language change or variable change, or talk about things that seem irrelevant to my search. So I need a little guideance.

I would sketch out an algorithm like this:

  1. Determine the max length of the integer variable for the language.

  2. If a number is more than half the length of the max length of the variable split it in an array. (give a little play room)

  3. Array order [0] = the numbers most to the right [n-max] = numbers most to the left

    Ex. Num: 29392023 Array[0]:23, Array[1]: 20, array[2]: 39, array[3]:29

Since I established half the length of the variable as the mark off point I can then calculate the ones, tenths, hundredths, etc. Place via the halfway mark so that if a variable max length was 10 digits from 0 to 9999999999 then I know that by halfing that to five digits give me some play room.

So if I add or multiply I can have a variable checker function that see that the sixth digit (from the right) of array[0] is the same place as the first digit (from the right) of array[1].

Dividing and subtracting have their own issues which I haven't thought about yet.

I would like to know about the best implementations of supporting larger numbers than the program can.

© Programmers or respective owner

Related posts about math

Related posts about variables