Skip to content

Commit

Permalink
Add options: --RiemannR && --R-inverse
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Feb 9, 2024
1 parent 0702ac5 commit c6906b5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions doc/primesieve.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ OPTIONS
*-q, --quiet*::
Quiet mode, prints less output.

*-R, --RiemannR*::
Approximate PrimePi(x) using the Riemann R function: R(x).

*--R-inverse*::
Approximate the nth prime using the inverse Riemann R function: R^-1(x).

*-s, --size*='SIZE'::
Set the size of the sieve array in KiB, 16 \<= 'SIZE' \<= 8192. By default
primesieve uses a sieve size that matches your CPU's L1 cache size (per
Expand Down
9 changes: 8 additions & 1 deletion src/app/cmdoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// @brief Parse command-line options for the primesieve console
/// (terminal) application.
///
/// Copyright (C) 2022 Kim Walisch, <[email protected]>
/// Copyright (C) 2024 Kim Walisch, <[email protected]>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand Down Expand Up @@ -44,6 +44,8 @@ enum OptionID
OPTION_DISTANCE,
OPTION_PRINT,
OPTION_QUIET,
OPTION_R,
OPTION_R_INVERSE,
OPTION_SIZE,
OPTION_TEST,
OPTION_THREADS,
Expand Down Expand Up @@ -380,6 +382,9 @@ CmdOptions parseOptions(int argc, char* argv[])
{ "--print", std::make_pair(OPTION_PRINT, OPTIONAL_PARAM) },
{ "-q", std::make_pair(OPTION_QUIET, NO_PARAM) },
{ "--quiet", std::make_pair(OPTION_QUIET, NO_PARAM) },
{ "-R", std::make_pair(OPTION_R, NO_PARAM) },
{ "--RiemannR", std::make_pair(OPTION_R, NO_PARAM) },
{ "--R-inverse", std::make_pair(OPTION_R_INVERSE, NO_PARAM) },
{ "-s", std::make_pair(OPTION_SIZE, REQUIRED_PARAM) },
{ "--size", std::make_pair(OPTION_SIZE, REQUIRED_PARAM) },
{ "--test", std::make_pair(OPTION_TEST, NO_PARAM) },
Expand Down Expand Up @@ -408,6 +413,8 @@ CmdOptions parseOptions(int argc, char* argv[])
case OPTION_QUIET: opts.quiet = true; break;
case OPTION_NTH_PRIME: opts.nthPrime = true; break;
case OPTION_NO_STATUS: opts.status = false; break;
case OPTION_R: opts.RiemannR = true; break;
case OPTION_R_INVERSE: opts.RiemannR_inverse = true; break;
case OPTION_TIME: opts.time = true; break;
case OPTION_NUMBER: opts.numbers.push_back(opt.getValue<uint64_t>()); break;
case OPTION_HELP: help(/* exitCode */ 0); break;
Expand Down
4 changes: 3 additions & 1 deletion src/app/cmdoptions.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///
/// @file cmdoptions.hpp
///
/// Copyright (C) 2023 Kim Walisch, <[email protected]>
/// Copyright (C) 2024 Kim Walisch, <[email protected]>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -21,6 +21,8 @@ struct CmdOptions
int threads = 0;
bool quiet = false;
bool nthPrime = false;
bool RiemannR = false;
bool RiemannR_inverse = false;
bool status = true;
bool time = false;
};
Expand Down
4 changes: 4 additions & 0 deletions src/app/help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ void help(int exitCode)
" print twin primes: -p2 or --print=2,\n"
" print prime triplets: -p3 or --print=3, ...\n"
" -q, --quiet Quiet mode, prints less output.\n"
" -R, --RiemannR Riemann R function, very accurate\n"
" approximation of PrimePi(x).\n"
" --R-inverse Inverse Riemann R function, very accurate\n"
" approximation of the nth prime.\n"
" -s, --size=SIZE Set the sieve size in KiB, SIZE <= 8192.\n"
" By default primesieve uses a sieve size that\n"
" matches your CPU's L1 cache size (per core) or is\n"
Expand Down
7 changes: 6 additions & 1 deletion src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
/// @file main.cpp
/// @brief primesieve console application.
///
/// Copyright (C) 2023 Kim Walisch, <[email protected]>
/// Copyright (C) 2024 Kim Walisch, <[email protected]>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///

#include <primesieve/ParallelSieve.hpp>
#include <primesieve/nthPrimeApprox.hpp>
#include <primesieve/Vector.hpp>
#include "cmdoptions.hpp"

Expand Down Expand Up @@ -136,6 +137,10 @@ int main(int argc, char* argv[])

if (opt.nthPrime)
nthPrime(opt);
else if (opt.RiemannR)
std::cout << Ri(opt.numbers[0]) << std::endl;
else if (opt.RiemannR_inverse)
std::cout << Ri_inverse(opt.numbers[0]) << std::endl;
else
sieve(opt);
}
Expand Down

0 comments on commit c6906b5

Please sign in to comment.