Category talk:Wren-i64: Difference between revisions

Added I64.modMul method.
(Bug fix.)
(Added I64.modMul method.)
Line 115:
}
return (neg) ? -s : s
}
 
// Returns an I64 object equal in value to 'x' multiplied by 'n' modulo 'mod'.
// The arguments can either be I64 objects or Nums but 'mod' must be non-zero.
static modMul(x, n, mod) {
if (!(x is I64)) x = from(x)
if (!(n is I64)) n = from(n)
if (!(mod is I64)) mod = from(mod)
if (mod.isZero) Fiber.abort("Cannot take modMul with modulus 0.")
var sign = x.sign * n.sign
var mag = U64.modMul(x.abs, n.abs, mod.abs).toI64
return mag * sign
}
 
Line 132 ⟶ 144:
while (exp > 0) {
if (base.isZero) return zero
if (exp.isOdd) r.set(modMul(r *, base) %, mod))
exp.rsh(1)
base.square.remset(modMul(base, base, mod))
}
return r
9,476

edits