Category talk:Wren-i64: Difference between revisions

→‎Source code (Wren): Added largestPrime and prev{rime
(→‎Source code (Wren): Fixed some minor issues and improved U64.isPrime method.)
(→‎Source code (Wren): Added largestPrime and prev{rime)
Line 407:
static maxSafe { from(9007199254740991) }
static maxU32 { from(4294967295) }
 
// Returns the largest prime less than 2^64.
static largestPrime { U64.fromStr("18446744073709551557") }
 
// Returns a U64 object equal in value to 'x' raised to the power of 'n'.
Line 688 ⟶ 691:
static nextPrime(x) {
if (x is Num) x = from(x)
if (x < two) return U64.two
var n = x.isEven ? x + one : x + two
while (true) {
if (isPrime(n)) return n
n.add(two)
}
}
 
// Returns the previous prime number less than 'x' or null if there isn't one.
static prevPrime(x) {
if (x is Num) x = from(x)
if (x < three) return null
if (x == three) return U64.two
var n = x.isEven ? x - one : x - two
while (true) {
if (isPrime(n)) return n
n.sub(two)
}
}
9,476

edits