prevprime

Next smaller prime

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

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