Math.pow()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Math.pow() は静的メソッドで、基数をべき乗した値を返します。

𝙼𝚊𝚝𝚑.𝚙𝚘𝚠(𝚡,𝚢)=xy\mathtt{\operatorname{Math.pow}(x, y)} = x^y

試してみましょう

console.log(Math.pow(7, 3));
// Expected output: 343

console.log(Math.pow(4, 0.5));
// Expected output: 2

console.log(Math.pow(7, -2));
// Expected output: 0.02040816326530612
//                  (1/49)

console.log(Math.pow(-7, 0.5));
// Expected output: NaN

構文

js
Math.pow(base, exponent)

引数

base

底となる数です。

exponent

base を累乗する指数です。

返値

base を表す数値を exponent 乗した値。以下のいずれかの場合は、 NaN を返します。

  • exponentNaN である。
  • baseNaN で、exponent0 以外である。
  • base が ±1 で、 exponent が ±Infinity である。
  • base < 0 で、 exponent が整数ではない。

解説

Math.pow()** 演算子と同等ですが、 Math.pow() は数値のみを受け入れるという点が異なります。

Math.pow(NaN, 0)(および同等の NaN ** 0)は、 NaN が数学演算で伝播しない唯一のケースです。これは、オペランドが NaN であるにもかかわらず 1 を返します。さらに、 base が 1 で exponent が無限大(±Infinity または NaN)である場合の動作は、結果が 1 となることを規定している IEEE 754 とは異なり、 JavaScript では元の動作との後方互換性を維持するために NaN を返します。

pow()Math の静的メソッドなので、常に Math.pow() として使用し、自分で Math オブジェクトを生成してそのメソッドとして使用しないでください。 (Math にはコンストラクターがありません)。

Math.pow() の使用

js
// 単純
Math.pow(7, 2); // 49
Math.pow(7, 3); // 343
Math.pow(2, 10); // 1024

// 小数のべき乗
Math.pow(4, 0.5); // 2 (4 の平方根)
Math.pow(8, 1 / 3); // 2 (8 の立方根)
Math.pow(2, 0.5); // 1.4142135623730951 (2 の平方根)
Math.pow(2, 1 / 3); // 1.2599210498948732 (2 の立方根)

// 負の数のべき乗
Math.pow(7, -2); // 0.02040816326530612 (1/49)
Math.pow(8, -1 / 3); // 0.5

// 負の数の底
Math.pow(-7, 2); // 49 (2 乗は正の数)
Math.pow(-7, 3); // -343 (3 乗は負の数)
Math.pow(-7, 0.5); // NaN (負の数には実数の平方根がない)
// Due to "even" and "odd" roots laying close to each other,
// and limits in the floating number precision,
// negative bases with fractional exponents always return NaN,
// even when the mathematical result is real
Math.pow(-7, 1 / 3); // NaN

// Zero and infinity
Math.pow(0, 0); // 1 (任意の数 ** ±0 is 1)
Math.pow(Infinity, 0.1); // Infinity (正の指数)
Math.pow(Infinity, -1); // 0 (負の指数)
Math.pow(-Infinity, 1); // -Infinity (正の奇数の整数の指数)
Math.pow(-Infinity, 1.5); // Infinity (正の指数)
Math.pow(-Infinity, -1); // -0 (負の奇数の整数の指数)
Math.pow(-Infinity, -1.5); // 0 (負の指数)
Math.pow(0, 1); // 0 (正の指数)
Math.pow(0, -1); // Infinity (負の指数)
Math.pow(-0, 1); // -0 (正の奇数の整数の指数)
Math.pow(-0, 1.5); // 0 (正の指数)
Math.pow(-0, -1); // -Infinity (負の奇数の整数の指数)
Math.pow(-0, -1.5); // Infinity (負の指数)
Math.pow(0.9, Infinity); // 0
Math.pow(1, Infinity); // NaN
Math.pow(1.1, Infinity); // Infinity
Math.pow(0.9, -Infinity); // Infinity
Math.pow(1, -Infinity); // NaN
Math.pow(1.1, -Infinity); // 0

// NaN: only Math.pow(NaN, 0) does not result in NaN
Math.pow(NaN, 0); // 1
Math.pow(NaN, 1); // NaN
Math.pow(1, NaN); // NaN

仕様書

Specification
ECMAScript® 2025 Language Specification
# sec-math.pow

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
pow

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報