def Mag.pow

bend-kit-bignum@0.1.0.0 · bigint.bend:261

import bend-kit-bignum@0.1.0.0/bigint.bend as Bigint
import Base

261# b^e * acc by squaring; e <= f, and e halves as f counts down.
262def Mag.pow(+f: Nat, +b: List<&2, U32>, +e: Nat, +acc: List<&2, U32>) ->
263  List<&2, U32>:
264  match f:
265    case 0n:
266      acc
267    case 1n+g:
268      +h = Nat.div(e, 2n)
269      +acc2 = Mag.if(List<&2, U32>, Nat.is_eq(Nat.mod(e, 2n), 1n),
270        u => Mag.mul(acc, b), u => acc)
271      Mag.if(List<&2, U32>, Nat.is_eq(h, 0n), u => acc2,
272        u => Mag.pow(g, Mag.mul(b, b), h, acc2))

Uses (8)

Used by (1)