# Big Integers

## version 1 by Jeremy John Reeder

**Version 1 of Big Integers by Jeremy John Reeder begins here.**

[Allows addition and multiplication of texts which represent integers. This is a work-around for the 32-bit limitation of Inform's native arithmetic operations.]

[To be implemented in the future:

* Subtraction

* Division

* Negative integers]

To decide which number is the numeric equivalent of (T - some text):

if there is a text of T in the Table of Number Parsing:

decide on the number corresponding to a text of T in the Table of Number Parsing;

decide on zero.

[TODO: parse multi-digit numbers]**Table 1 - Number Parsing**

Text | Number |

"0" | 0 |

"1" | 1 |

"2" | 2 |

"3" | 3 |

"4" | 4 |

"5" | 5 |

"6" | 6 |

"7" | 7 |

"8" | 8 |

"9" | 9 |

let the answer be "";

let the carried digit be zero;

while A is not "" or B is not "" or the carried digit is not zero:

let the ones digit of A be the numeric equivalent of the last character in A;

let the ones digit of B be the numeric equivalent of the last character in B;

let the sum of the ones digits be (ones digit of A) plus (ones digit of B) plus (carried digit);

now the answer is "[remainder after dividing the sum of the ones digits by ten][answer]";

now the carried digit is (sum of the ones digits) divided by ten;

now A is the first (number of characters in A minus one) characters in A;

now B is the first (number of characters in B minus one) characters in B;

decide on the answer.

To decide which text is (A - some text) plus (B - a number):

decide on A plus "[B]".

To decide which text is (A - a number) plus (B - some text):

decide on "[A]" plus B.

To decide which text is (A - some text) times (B - some text):

let the answer be "";

let the carried digit be zero;

while A is not "" or B is not "" or the carried digit is not zero:

let the ones digit of A be the numeric equivalent of the last character in A;

let the ones digit of B be the numeric equivalent of the last character in B;

let the product of the ones digits be (ones digit of A) times (ones digit of B) plus (carried digit);

now the answer is "[remainder after dividing the product of the ones digits by ten][answer]";

now the carried digit is (product of the ones digits) divided by ten;

now A is the first (number of characters in A minus one) characters in A;

now B is the first (number of characters in B minus one) characters in B;

decide on the answer.

To decide which text is (A - some text) times (B - a number):

decide on A times "[B]".

To decide which text is (A - a number) times (B - some text):

decide on "[A]" times B.

To decide which text is the first (N - a number) characters in (T - some text):

let R be "";

repeat with X running from 1 to N:

now R is "[R][character number (X) in T]";

decide on R.

To decide which text is the last character in (T - some text):

let N be the number of characters in T;

decide on character number (N) in T.

To decide which number is the greater of (A - a number) and (B - a number):

if A is greater than B:

decide on A;

otherwise:

decide on B.

To decide which text is the greater of (A - some text) and (B - some text):

if the number of characters in A is greater than the number of characters in B:

decide on A;

if the number of characters in B is greater than the number of characters in A:

decide on B;

otherwise:

let the two numbers be a list of texts;

add A to the two numbers;

add B to the two numbers;

sort the two numbers;

decide on entry two in the two numbers.

Big Integers ends here.