# MathLib.hypot()

## Examples

The length of the hypothenuse in a right triangle, where the catheti have length 3 and 4, can be calculated with:```
var length = MathLib.hypot(3, 4);
// The value of length is now 5
```

## Specification

MathLib.hypot accepts any number of arguments. The type of all arguments has to be "number".- MathLib.hypot(x, y, ...) = +∞ if any argument is infinite
- MathLib.hypot(x, y, ...) = NaN if any argument is NaN, and none infinite
- MathLib.hypot(x, y, ...) = +0 if all arguments are ±0
- Otherwise MathLib.hypot(x, y, ...) = the square root of the sum of the squared arguments

## Implementation

The implementation is based on the following identity $$\sqrt{{x}^{2}+{y}^{2}}=\left|x\right|\sqrt{1+{\left(\frac{y}{x}\right)}^{2}}$$ (with $\left|x\right|>\left|y\right|$). This implementation has the advantage that it has no problems with underflows and overflows like a naive implementation would have. If three or more arguments are passed, the computation is made with the following identity: $$\mathrm{\text{hypot}}(a,b,c)=\mathrm{\text{hypot}}(a,\mathrm{\text{hypot}}(b,c\left)\right)$$## Tests

## Links

- Hypot on Wikipedia

Categories: n-ary Function