R/fermat.R

#' Test an integer for primality with Fermat's little theorem
#'
#' This is an example function for making R packages and R documentation
#' with \code{\link[roxygen2:roxygenize]{roxygen2}} and \code{\link[roxygen2:roxygenize]{roxygenize}}.
#' 
#' Fermat's little theorem states that if \eqn{n} is a prime
#' number and \eqn{a} is any positive integer less than \eqn{n},
#' then \eqn{a} raised to the \eqn{n}th power is congruent to
#' \eqn{a\ modulo\ n}{a modulo n}.
#'
#' @param n the integer to test for primality
#' @return Whether the integer passes the Fermat test
#' for a randomized \eqn{0 < a < n} no workyATcallGraphPrimitives
#' @export
#' @note \code{fermat.test} doesn't work for integers above
#' approximately fifteen because modulus loses precision.
#' @references
#' \url{http://en.wikipedia.org/wiki/Fermat's_little_theorem}
#' @author Peter Danenberg \email{pcd@@roxygen.org}
#' 
fermat.test <- function(n)
	{
	a <- floor(runif(1, min=1, max=n))
	a ^ n %% n == a
	}

Try the modiscloud package in your browser

Any scripts or data that you put into this service are public.

modiscloud documentation built on May 2, 2019, 5:19 p.m.