I've been writing a few methods to treat a LinkedList in Java as an infinite array for scientific notation. The first index is the integer, and the rest are decimals. I've been working on a division algorithm between two LinkedLists, but have had a lot of trouble. Right now, my code goes through an infinite loop. If somebody could please help me find the issue (I don't need a solution written for me xD), I would be nearly finished. Assume that other methods I wrote are correct.
public static LinkedList<Integer> divide(LinkedList<Integer> a, LinkedList<Integer> b) {
LinkedList<Integer> arr = new LinkedList<Integer>();
LinkedList<Integer> base = new LinkedList<Integer>();
base.add(a.get(0));
boolean incomplete = true;
int i = 0;
while (incomplete) {
LinkedList<Integer> multiplier = new LinkedList<Integer>();
multiplier.add(1);
while (LinkedListMethods.lessThan(LinkedListMethods.multiply(b, multiplier), base)) {
multiplier.set(0, multiplier.get(0) + 1);
}
multiplier.set(0, multiplier.get(0) - 1);
LinkedList<Integer> multiple = new LinkedList<Integer>();
multiple = LinkedListMethods.multiply(b, multiplier);
base = LinkedListMethods.subtract(base, multiple);
arr.add(multiplier.get(0));
base = LinkedListMethods.clean(base);
if (i == a.size() - 1 && base.get(0) == 0) {
incomplete = false;
} else if (i == arr.size() - 1) {
a.add(0);
}
i++;
}
return clean(arr);
}
Thank you for any help!
Edit 1: lessThan(a, b) returns true if a < b (it's tested to work)
Edit 2: The other methods are up at http://javaman.net/code/larger-decimals (it's compact and unreadable for some reason)