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

Previous Prime Function
Math Arithmetic Class

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

"Previous Prime Number"
Returns the previous, smaller prime number.
Returns the largest prime number less than the argument.

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

Special handling:

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

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