Category talk:Wren-math: Difference between revisions

→‎Source code: Added Math.nextPower method
(→‎Source code: Added Math.lgamma method.)
(→‎Source code: Added Math.nextPower method)
Line 65:
// Convenience version of above method which uses 0 for the 'mode' parameter.
static toPlaces(x, p) { toPlaces(x, p, 0) }
 
// The power of 'p' which equals or first exceeds a non-negative number 'x'.
// 'p' must be an integer greater than 1.
// Returns a two element list containing the power and the exponent.
static nextPower(x, p) {
if (!((x is Num) && x >= 0)) Fiber.abort("x must be a non-negative number.")
if (!((p is Num) && p.isInteger && p > 1)) Fiber.abort("p must be an integer > 1.")
if (x <= 1) return [1, 0]
var pow = 1
var count = 0
while (x > pow) {
pow = pow * p
count = count + 1
}
return [pow, count]
}
 
// Gamma function using Lanczos approximation.
9,479

edits