prevprime

Next smaller prime

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

prevprime(a)

Description

prevprime(a) returns the greatest prime number less or equal than a. If a < 2, then prevprime(a) returns FAIL.

prevprime returns the function call with evaluated argument if the argument is not an integer.

prevprime returns an error if the argument evaluates to zero or a negative integer.

Examples

Example 1

Computing the largest prime p ≤ 15485865:

prevprime(15485865)

Example 2

There are no primes smaller than 2:

prevprime(1)

Parameters

a

A positive integer

Return Values

prevprime(a) returns either a natural number or FAIL.

Algorithms

prevprime uses the probabilistic prime test isprime and may therefore return false results with small probability.

See Also

MuPAD Functions

Was this topic helpful?