R/euclidean.R

Defines functions euclidean

Documented in euclidean

#' Function to calculate greatest common divisor of two numbers (x and y) using the Euclidean algorithm based on pseudocode from Wikipedia.
#'@param x a numeric scalars or integers.
#'@param y a numeric scalars or integers.
#' @source \url{https://en.wikipedia.org/wiki/Euclidean_distance}
#' @export
euclidean <- function(x, y){
        stopifnot((is.numeric(x) | is.integer(x)) & (is.numeric(y) | is.integer(y)))
        while (y !=0 ){
                z <- y
                y <- x %% y
                x <- z
        }
        return(x)
}
drowsygoat/lab3.package documentation built on Dec. 20, 2021, 1:19 a.m.