<-- Previous || Up || Next -->

Next Prime Function
Math Arithmetic Class

Public Function NextPrime( _
    ByVal vX As Variant _
    ) As Variant

"Next Prime Number"
Returns the next larger prime number.
Returns the smallest prime number greater than the argument.

Examples:
    NextPrime(-6) = -5
    NextPrime(-5) = -3
    NextPrime(-3) = -2
    NextPrime(-2) = 2
    NextPrime(-1) = 2
    NextPrime(1) = 2
    NextPrime(2) = 3
    NextPrime(3) = 5
    NextPrime(5) = 7
    NextPrime(7) = 11
See also:
    NextPrimeSample Subroutine
    PreviousPrime Function
    NthPrime Function
    IsPrime Function
vX: The number whose next-larger prime number is returned. Function returns Null if vX is Null or cannot be fixed up to a number.

Special handling:

    If -5 <= X < -3 Then Return -3.
    If -3 <= X < -2 Then Return -2.
    If -2 <= X <  2 Then Return  2.
    If  2 <= X <  3 Then Return  3.

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.