Category talk:Wren-big: Difference between revisions
Content added Content deleted
(→Source code: Added BigRat.roundUp method.) |
(→Source code: Added BigInt.prevPrime method.) |
||
Line 967: | Line 967: | ||
} |
} |
||
// Returns the previous probable prime number less than 'this' or null if there isn't one. |
|||
⚫ | |||
prevPrime(iterations) { |
|||
if (this < BigInt.three) return null |
|||
if (this == BigInt.three) return BigInt.two |
|||
var n = isEven ? this - 1 : this - 2 |
|||
while (true) { |
|||
if (n.isProbablePrime(iterations)) return n |
|||
n = n - 2 |
|||
} |
|||
} |
|||
⚫ | |||
nextPrime { nextPrime(5) } |
nextPrime { nextPrime(5) } |
||
prevPrime { prevPrime(5) } |
|||
// Negates a BigInt. |
// Negates a BigInt. |