vecnorm(x, p = 2)
Computation of the 2 norm is based on the function dnrm2 Linpack BLAS (Dongarra et al. 1979). For 1 < p < Inf, p-norms are computed so as to avoid overflow and underflow. The numerical value of a norm may differ for vectors which have the same elements appearing in a different order. Sorting a vector so that the elements of smallest modulus appear first may help reduce this roundoff error.
Dongarra, J. J., Bunch, J. R., Moler, C. B., and Stewart, G. W. (1979). Linpack User's Guide. SIAM, Philadelphia.
x <- rnorm(100) sqrt(sum(x*x)) vecnorm(x) x <- rep(sqrt(.Machine$double.xmax), 4) sqrt(sum(x*x)) vecnorm(x) sum(abs(x)) vecnorm(x, p = 1) max(abs(x)) vecnorm(x, p = Inf)