MathLib.hypot() calculates the square root of the sum of the squared arguments. The hypot implementation can handle any number of arguments.
ExamplesThe 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
SpecificationMathLib.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
ImplementationThe implementation is based on the following identity (with ). 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:
- Hypot on Wikipedia
Categories: n-ary Function