Category talk:Wren-long: Difference between revisions
Content added Content deleted
(→Source code: Removed some redundant lines.) |
(→Source code: Added largestPrime and prevPrime methods to ULong class.) |
||
Line 78: | Line 78: | ||
// Returns the largest ULong = 2^64-1 = 18446744073709551615 |
// Returns the largest ULong = 2^64-1 = 18446744073709551615 |
||
static largest { lohi_(4294967295, 4294967295) } |
static largest { lohi_(4294967295, 4294967295) } |
||
// Returns the largest prime less than 2^64. |
|||
static largestPrime { ULong.new("18446744073709551557") } |
|||
// Returns the smallest ULong = 0 |
// Returns the smallest ULong = 0 |
||
Line 486: | Line 489: | ||
if (n.isPrime) return n |
if (n.isPrime) return n |
||
n = n + ULong.two |
n = n + ULong.two |
||
} |
|||
} |
|||
// Returns the previous prime number less than the current instance or null if there isn't one. |
|||
prevPrime { |
|||
if (this < ULong.three) return null |
|||
if (this == ULong.three) return ULong.two |
|||
var n = isEven ? this - ULong.one : this - ULong.two |
|||
while (true) { |
|||
if (n.isPrime) return n |
|||
n = n - ULong.two |
|||
} |
} |
||
} |
} |