Category talk:Wren-long: Difference between revisions
Content added Content deleted
(Bug fix.) |
(Made modMul, modPow more robust.) |
||
Line 708: | Line 708: | ||
// Returns the current instance multiplied by 'n' modulo 'mod'. |
// Returns the current instance multiplied by 'n' modulo 'mod'. |
||
modMul(n, mod) { |
modMul(n, mod) { |
||
if (!(n is ULong)) n = ULong.new(n) |
|||
if (!(mod is ULong)) mod = ULong.new(mod) |
|||
if (mod.isZero) Fiber.abort("Cannot take modMul with modulus 0.") |
|||
var x = ULong.zero |
var x = ULong.zero |
||
var y = this |
var y = this |
||
Line 1,295: | Line 1,298: | ||
// Returns the current instance multiplied by 'n' modulo 'mod'. |
// Returns the current instance multiplied by 'n' modulo 'mod'. |
||
modMul(n, mod) { Long.sigma_(_sig, _mag.modMul(n, mod)) } |
modMul(n, mod) { Long.sigma_(_sig * n.sign , _mag.modMul(n.abs, mod.abs)) } |
||
// Returns the current instance to the power 'exp' modulo 'mod'. |
// Returns the current instance to the power 'exp' modulo 'mod'. |
||
modPow(exp, mod) { |
modPow(exp, mod) { |
||
if (!(exp is Long)) exp = Long.new(exp) |
|||
if (!(mod is Long)) mod = Long.new(mod) |
|||
var mag = _mag.modPow(exp, mod) |
var mag = _mag.modPow(exp, mod) |
||
var sign |
var sign |