R/gcd.R

Defines functions gcd

Documented in gcd

gcd <- function(x) {
    n <- length(x)
    if (n < 2) { 
        g <- x   
        warning("Input vector should normally have length greater than 1.")
    } else {
        ints <- x
        g <- ints[1]
        z <- .Fortran("gcd", as.integer(n), as.integer(ints), as.integer(g))
        g <- z[[3]]
    }
    return(g)
}

Try the MiscMath package in your browser

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

MiscMath documentation built on April 13, 2025, 9:07 a.m.