# Math.hypot()

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

$Math.hypot(v1,v2,…,vn)=∑i=1nvi2=v12+v22+…+vn2\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, ...

## 示例

### Using Math.hypot()

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)


## 向下兼容

if (!Math.hypot) Math.hypot = function() {
var y = 0, i = arguments.length;
while (i--) y += arguments[i] * arguments[i];
return Math.sqrt(y);
};


if (!Math.hypot) Math.hypot = function (x, y) {
// https://bugzilla.mozilla.org/show_bug.cgi?id=896264#c28
var max = 0;
var s = 0;
for (var i = 0; i < arguments.length; i += 1) {
var arg = Math.abs(Number(arguments[i]));
if (arg > max) {
s *= (max / arg) * (max / arg);
max = arg;
}
s += arg === 0 && max === 0 ? 0 : (arg / max) * (arg / max);
}
return max === 1 / 0 ? 1 / 0 : max * Math.sqrt(s);
};


## 规范

ECMAScript (ECMA-262)
Math.hypot

## 浏览器兼容性

Update compatibility data on GitHub
Desktop Mobile Server Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Chrome Full support 38 Edge Full support 12 Firefox Full support 27 IE No support No Opera Full support 25 Safari Full support 8 WebView Android Full support 38 Chrome Android Full support 38 Firefox Android Full support 27 Opera Android Full support 25 Safari iOS Full support 8 Samsung Internet Android Full support 3.0 nodejs Full support 0.12

Full support
Full support
No support
No support