As far as I can see this is what you are doing:
Example using 1/2 and 3/4...
Common Denominator = 4*2 = 8
Scale Numerators To CD = 1*4 + 3*2 = 10
but then you just add 10 to r4, 10 isn't the answer, it is 10/8: (r1+r2)/d12.
You are probably getting negative numbers because the integer is overloading, I'll explain: in your program you can have a fraction of 999/1000 so by your current method, assuming both fractions are 999/1000, you'd get this answer:
r1 = 999*1000 = 999,000
r2 = 999*1000 = 999,000
r3 = r1+r2 = 1,998,000
now if you run the program for 60 seconds it is going to be able to execute your loop thousands of times, lets say 2000 times (that would be once every 30ms which is probably slower that it would run), that means your sum at the end of the program would be
1,998,000 * 2000 = 3,996,000,000
I forget what the limit is for signed integers in DB but I'm pretty sure this is a big enough number to tip the scales. The reason you get a negative number is because of the way numbers are stored in memory. Let's say we have a puny computer that can only store 4-bit numbers, now if you know anything about binary you will know the biggest number we can make with 4 bits is 15:
1 2 4 8
x + x + x + x
1 1 1 1
Buuut, if we want to be able to do negative numbers we're going to have to use one of those bits to remember if the number is positive or negative. So our bits would be worth: -,1,2 and 4. You see how we can now only make -7 to +7, (note:this is why it's important to use the right data type, if we're not going to use negative numbers we should use an unsigned data type which allows bigger numbers). So what happens if we overload the data type? Let's count up until we overload...
0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = -7
1001 = -6
1010 = -5
1011 = -4
1100 = -3
1101 = -2
1110 = -1
1111 = -0
Did you wonder why 1000 is -7 and not -0? If we add one more you'll see why...
1111 = -0
0000 = 0
Using the loop of the bits in this way helps us use numbers as they are used in the real world, negative numbers decrease in value as they are added to until they eventually become positive.
I hope that helps.
PS. If you want to find out for yourself what the highest number you can store in an integer is you can write a very simple program that will show you. Try to figure it out before looking in this box.
while (x+1)>=0
inc x
endwhile
print "The largest number a signed integer can store is: ";x
wait key
end