File:  [Research Unix] / researchv10dc / cmd / icon / book / 18 / add3.icn
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:34 2018 UTC (8 years, 3 months ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Dan Cross

record largint(coeff,nextl)

procedure add(g1,g2,carry)
   local sum
   /carry := largint(0)	# default carry
   if /g1 & /g2 then return if carry.coeff ~= 0 then carry
   else &null
   if /g1 then return add(carry,g2)
   if /g2 then return add(g1,carry)
   sum := g1.coeff + g2.coeff + carry.coeff
   carry := largint(sum / base)
   return largint(sum % base,add(g1.nextl,g2.nextl,carry))
end

procedure large(s)
   if *s <= segsize then return largint(integer(s))
   else return largint(right(s,segsize),
      large(left(s,*s - segsize)))
end

procedure lstring(g)
   local s
   if /g.nextl then s := g.coeff
   else s := lstring(g.nextl) || right(g.coeff,segsize,"0")
   s ?:= (tab(upto(~'0') | -1) & tab(0))
   return s
end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.