up previous next
PrevPrime, PrevProbPrime --
find the previous prime number
|
PrevPrime(N: INT): INT
PrevProbPrime(N: INT): INT |
The first function computes the largest prime number smaller than
N.
If
N is too large then an error is signalled. The upper
limit depends on the computer you are using; it is probably
2^31-1
or
2^63-1.
The second function computes the largest probable prime number greater than
N.
To be absolutely certain the number produced is prime,
you must call
IsPrime
on it, but this may be very costly.
Both functions throw errors if given negative arguments. They also
throw errors if given arguments 0, 1 or 2.
PrevProbPrime uses
IsProbPrime
which cannot be interrupted, so be wary of inputs
larger than about
2^100000 (which already takes a few minutes).
/**/ PrevPrime(1000);
997
/**/ PrevProbPrime(10^50);
99999999999999999999999999999999999999999999999943
|