#how to do an add with carry chain?

1 messages · Page 1 of 1 (latest)

hollow swan
#

I am trying to add digits of a variable length number, and am using @addWithOverflow to detect carry out, though am unsure how to use the result as carry in for the next digit.

I would expect to find something like @adcWithOverflow(a: anytype, b: anytype, c: u1) though seemingly there isn't.

frail glen
#

conceptually, it does an addOverflow with a + b + c. So you can do the following and the compiler should figure it out:

addOverflowCarry(a, b, carry):
  out, c1 = addOverflow(a, b)
  out, c2 = addOverflow(out, carry)
  return out, c1 or c2
frail glen