# Math.hypot()

## 概述

Math.hypot() 函数返回它的所有参数的平方和的平方根，即：

$Math.hypot ( v 1 , v 2 , … , v n ) = ∑ i = 1 n v i 2 = v 1 2 + v 2 2 + … + v n 2 \mathtt{\operatorname{Math.hypot}(v_1, v_2, \dots, v_n)} = \sqrt{\sum_{i=1}^n v_i^2} = \sqrt{v_1^2 + v_2^2 + \dots + v_n^2}$

## 语法

Math.hypot([value1[,value2, ...]]) 

### 参数

value1, value2, ...

## 示例

Math.hypot(3, 4)        // 5
Math.hypot(3, 4, 5)     // 7.0710678118654755
Math.hypot()            // 0
Math.hypot(NaN)         // NaN
Math.hypot(3, 4, "foo") // NaN, +"foo" => NaN
Math.hypot(3, 4, "5")   // 7.0710678118654755, +"5" => 5
Math.hypot(-3)          // 3, the same as Math.abs(-3)


## Polyfill

if (!Math.hypot) {
Math.hypot = function hypot() {
var y = 0;
var length = arguments.length;

for (var i = 0; i < length; i++) {
if(arguments[i] === Infinity || arguments[i] === -Infinity) {
return Infinity;
}
y += arguments[i] * arguments[i];
}
return Math.sqrt(y);
};
}

## 规范

ECMAScript 2015 (6th Edition, ECMA-262)
Math.hypot
Standard

## 浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 38 27 (27) 未实现 25 7.1
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 未实现 27.0 (27) 未实现 未实现 未实现