Big Math

Geoff Canyon gcanyon at
Sat Nov 14 16:31:59 EST 2015

I have not tested these thoroughly enough, but they worked for what I
needed them for, so I'm putting them out there. Bugs/improvements welcome.

To add two arbitrarily large numbers -- must both be positive:

function bAdd x,y
   put 0 into c
   repeat with i = 14 to max(length(x),length(y)) step 14
      add char -i to 13 - i of x + char -i to 13 - i of y to c
      put char -14 to -1 of ("00000000000000" & c) before r
      delete char -14 to -1 of c
   end repeat
   return c & r
end bAdd

To div (not divide) an arbitrarily large number by any LC-capable number
(up to about 14 digits) -- could be that both must be positive:

function bigDiv X,D
   repeat with i = 1 to length(X) div 14 step 14
      put char i to i + 13 of X div D after Q
      put char i to i + 13 of X mod D into char i to i + 13 of X
   end repeat
   return Q
end bigDiv

More information about the use-livecode mailing list