Category talk:Wren-big: Difference between revisions
Content added Content deleted
(→Source code: Added iroot and icbrt methods to BigInt class.) |
(→Source code: Added BigInt.factorial method.) |
||
Line 676: | Line 676: | ||
if (!(b is BigInt)) b = BigInt.new(b) |
if (!(b is BigInt)) b = BigInt.new(b) |
||
return a / gcd(a, b) * b |
return a / gcd(a, b) * b |
||
} |
|||
// Returns the factorial of 'n'. |
|||
static factorial(n) { |
|||
if (!(n is Num && n >= 0)) Fiber.abort("Argument must be a non-negative integer") |
|||
if (n < 2) return BigInt.one |
|||
var fact = BigInt.one |
|||
for (i in 2..n) fact = fact * i |
|||
return fact |
|||
} |
} |
||