https://github.com/cran/pracma
Revision b5e4bf28fcba9f5eaffbeecfb0bc307452d074ee authored by Hans W. Borchers on 01 November 2014, 00:00:00 UTC, committed by Gabor Csardi on 01 November 2014, 00:00:00 UTC
1 parent d57c14d
Tip revision: b5e4bf28fcba9f5eaffbeecfb0bc307452d074ee authored by Hans W. Borchers on 01 November 2014, 00:00:00 UTC
version 1.7.7
version 1.7.7
Tip revision: b5e4bf2
hypot.R
##
## h y p o t h . R
##
hypot <- function(x, y) {
if ((length(x) == 0 && is.numeric(y) && length(y) <= 1) ||
(length(y) == 0 && is.numeric(x) && length(x) <= 1))
return(c())
if (!is.numeric(x) && !is.complex(x) || !is.numeric(y) && !is.complex(y))
stop("Arguments 'x' and 'y' must be numeric or complex.")
if ((is.vector(x) && is.vector(y) && length(x) != length(y)) ||
(is.matrix(x) && is.matrix(y) && dim(x) != dim(y)) ||
(is.vector(x) && is.matrix(y)) || is.matrix(x) && is.vector(y))
stop("Arguments 'x' and 'y' must be of the same size.")
x <- abs(x); y <- abs(y)
m <- pmin(x, y); M <- pmax(x, y)
ifelse(M == 0, 0, M * sqrt(1 + (m / M)^2))
}
Computing file changes ...