hypot {essentials}R Documentation

Hypotenuse

Description

Compute the length of the hypotenuse.

Usage

hypot(x, y)

Arguments

x, y

numeric vectors; the lengths of non-hypotenuse sides, the sides adjacent to the right angle.

Details

The hypotenuse is the longest side of a right-angled triangle, the side opposite the right angle. The length of the hypotenuse is defined as:

\sqrt(x^2 + y^2)

If x[i] or y[i] is infinite, the result in the i-th position will always be Inf. Otherwise, if x[i] or y[i] is NA or NaN, the result in the i-th position will be NaN. Otherwise, if the absolute value of x[i] is considerably larger than the absolute value of y[i], the result in the i-th position will be the absolute value of x[i] (and vice versa). Otherwise, the value will be calculated using the above definition.

Value

A numeric vector. If x or y is a zero-length vector the result has length zero. Otherwise, the result has length of the maximum of the lengths of x and y.

Examples

hypot(Inf, NaN)     # still positive infinity
hypot(NaN, 0)       # NaN
hypot(NA_real_, 0)  # NaN


## numbers whose squares would overflow normally are handled well
hypot(.Machine$double.xmax, 5     )
hypot(1e+300              , 1e+300)


hypot(3, 4)         # 5

[Package essentials version 0.1.0 Index]