hypotenuse: Dumb hypotenuse function.

Description Usage Arguments Value Note References See Also Examples

View source: R/hypotenuse.R

Description

Calculate the (Pythagorean) hypotenuse of two numeric vectors using the obvious algorithm.

Usage

1
  hypotenuse(x, y)

Arguments

x

A numeric vector.

y

A numeric vector.

Value

A numeric vector of the hyptenuse of the inputs.

Note

This algorithm fails when the inputs are very large of very small, making it unsuitable for real-world use.

References

Cleve Moler (MATLAB creator and discoverer of the Moler-Morrison algorithm for calculating hypotenuses) discusses the pro and cons of several algorithms here. http://blogs.mathworks.com/cleve/2012/07/30/pythagorean-addition

See Also

hypot

Examples

1
2
3
hypotenuse(5, 12)           #okay
hypotenuse(1e-300, 1e-300)  #fails
hypotenuse(1e300, 1e300)    #fails

Example output

[1] 13
[1] 0
[1] Inf

learningr documentation built on Oct. 2, 2019, 5:04 p.m.