Want to add some really big numbers together that just won't fit within the Integer range? This snippet adds two really large numbers together by representing them as strings. Note that it probably only works with postive numbers.
a$ = "643365438404"
b$ = "95447549445"
q as integer
w as integer
q = 643365438404
w = 95447549445
print q," + ",w," = ",q + w
print "643365438404 + 95447549445 = 738812987849"
print a$," + ",b$," = ",add(a$, b$)
suspend for key
end
function add(n1 as string, n2 as string)
if len(n1) < len(n2)
temp$ = n1
n1 = n2
n2 = temp$
endif
ln1 = len(n1)
ln2 = len(n2)
answer$ = ""
remainder = 0
for a = 0 to len(n1)-1
x = val(mid$(n1, ln1-a))
if a < len(n2)
y = val(mid$(n2, ln2-a))
else
y = 0
endif
ans = x+y+remainder
r$ = str$(ans)
if ans > 9
answer$ = right$(r$,1) + answer$
remainder = val(left$(r$, len(r$)-1))
else
answer$ = r$ + answer$
remainder = 0
endif
next a
if remainder > 0 then answer$ = str$(remainder) + answer$
endfunction answer$