*! Version 1.0.1 17 April 2014
help getprime

Title

getprime -- Gets the prime number closer to the specified
number

Syntax

getprime number [, above print
scalar(name)]

Description

getprime gets the prime number that is closer to number.

This becomes useful, for example, when wanting to have about a certain
number of draws for simulation. In particular for Hemmersley and Halton
sequences it's better to make the number of draws prime. This way you just enter
the number of draws you want as number and getprime finds the prime
number closer to it, whether above or below depending on whether you specified
above or not. I'm sure you will find many other applications.

getprime uses, and thus requires, the command isprime.

Options

above specifies that the prime number ought to be larger than
number. If omitted, getprime gets the prime number closer to
number but below it.

print specifies that getprime displays the retrieved prime
number, and whether it is greater or lower than number, depending on
whether above was specified or not.

scalar(name) allows you to specify the name of a scalar to hold
the prime number so you can use it later.

Examples

. getprime 500

. return list

. getprime 350, above

. return list

. getprime 230, a pr

. return list

. getprime 125, a sca(prime)

. display prime

Stored results

getprime stores the following in r():

Scalars

r(pnum) The prime number.

r(rnum) The submitted number.

Author

Alfonso Sánchez-Peñalver

Lock Haven University of Pennsylvania

Lock Haven, PA USA

asp155@lhup.edu