Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Prime Numbers

#include <boost/math/special_functions/prime.hpp>
namespace boost { namespace math {

template <class Policy>
boost::uint32_t prime(unsigned n, const Policy& pol);

boost::uint32_t prime(unsigned n);

static const unsigned max_prime = 10000;

}} // namespaces

The function prime provides fast table lookup to the first 10000 prime numbers (starting from 2 as the zeroth prime: as 1 isn't terribly useful in practice). There are two function signatures one of which takes an optional Policy as the second parameter to control error handling.

The constant max_prime is the largest value you can pass to prime without incurring an error.

Passing a value greater than max_prime results in a domain_error being raised.