https://github.com/cran/pracma
Raw File
Tip revision: 71455748623ef69836470c75c5f9384f6e872d45 authored by HwB on 28 June 2011, 00:00:00 UTC
version 0.6-3
Tip revision: 7145574
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.")

	sqrt(abs(x)^2 + abs(y)^2)
}
back to top