R/euclidean.R

Defines functions euclidean

Documented in euclidean

#' Algorithm for finding the greatest common divisor, Euclidean algorithm
#'@param a integer
#'@param b integer
#'@return an integer which is the gcd(a,b)
#'@references \url{https://en.wikipedia.org/wiki/Euclidean_algorithm}
#'@export
euclidean <- function(a,b) {
  stopifnot(is.numeric(a) & is.numeric(b) &
              a %% 1 == 0 & b %% 1 == 0)
  t <- 0
  while(b != 0) {
    t <- b
    b <- a %% b
    a <- t
  }
  return (a)
}
SimonJonsson/lab3 documentation built on May 14, 2019, 8:58 a.m.