From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../reference/global_objects/math/log2/index.html | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/math/log2/index.html (limited to 'files/ja/web/javascript/reference/global_objects/math/log2/index.html') diff --git a/files/ja/web/javascript/reference/global_objects/math/log2/index.html b/files/ja/web/javascript/reference/global_objects/math/log2/index.html new file mode 100644 index 0000000000..b7fadcb09e --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/math/log2/index.html @@ -0,0 +1,95 @@ +--- +title: Math.log2() +slug: Web/JavaScript/Reference/Global_Objects/Math/log2 +tags: + - ECMAScript 2015 + - JavaScript + - Math + - Method + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Math/log2 +--- +
{{JSRef}}
+ +

Math.log2() 関数は、数値の 2 を底とした対数を返します。

+ +

x>0,Math.log2(x)=log2(x)=the uniqueysuch that2y=x\forall x > 0, \mathtt{\operatorname{Math.log2}(x)} = \log_2(x) = \text{the unique} \; y \; \text{such that} \; 2^y = x

+ +
{{EmbedInteractiveExample("pages/js/math-log2.html")}}
+ + + +

構文

+ +
Math.log2(x)
+ +

引数

+ +
+
x
+
数値です。
+
+ +

返値

+ +

与えられた数値の 2 を底とした対数です。数値が負の数であった場合、 {{jsxref("NaN")}} が返されます。

+ +

解説

+ +

x の値が 0 未満であった場合、返値は常に {{jsxref("NaN")}} です。

+ +

log2()Math の静的メソッドであるため、生成した Math オブジェクトのメソッドとしてではなく、常に Math.log2() として使用するようにしてください (Math はコンストラクターではありません)。

+ +

この関数は Math.log(x) / Math.log(2) と同等です。 log2(e) には定数 {{jsxref("Math.LOG2E")}} を使用してください (これは 1 / {{jsxref("Math.LN2")}} です。)

+ +

ポリフィル

+ +

このポリフィルは Math.log2 関数をエミュレートします。なお、これは入力値によっては不正確な値を返すので (1 << 29 など)、ビットマスクで使用するときは {{jsxref("Math.round()")}} で囲んでください。

+ +
if (!Math.log2) Math.log2 = function(x) {
+  return Math.log(x) * Math.LOG2E;
+};
+
+ +

+ +

Math.log2() の使用

+ +
Math.log2(3);    // 1.584962500721156
+Math.log2(2);    // 1
+Math.log2(1);    // 0
+Math.log2(0);    // -Infinity
+Math.log2(-2);   // NaN
+Math.log2(1024); // 10
+
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-math.log2', 'Math.log2')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("javascript.builtins.Math.log2")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf