diff options
Diffstat (limited to 'files/de/web/javascript/reference/global_objects/math/clz32')
-rw-r--r-- | files/de/web/javascript/reference/global_objects/math/clz32/index.html | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/files/de/web/javascript/reference/global_objects/math/clz32/index.html b/files/de/web/javascript/reference/global_objects/math/clz32/index.html new file mode 100644 index 0000000000..ac7c78c4a7 --- /dev/null +++ b/files/de/web/javascript/reference/global_objects/math/clz32/index.html @@ -0,0 +1,112 @@ +--- +title: Math.clz32() +slug: Web/JavaScript/Reference/Global_Objects/Math/clz32 +tags: + - ECMAScript 2015 + - Java + - Math + - Method + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Math/clz32 +--- +<div>{{JSRef}}</div> + +<p>Die <strong><code>Math.clz32()</code></strong> Funktion zählt die führenden Nullbits in der 32-Bit binär Repräsentation einer Nummer.</p> + +<div>{{EmbedInteractiveExample("pages/js/math-clz32.html")}}</div> + + + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox"><code>Math.clz32(<var>x</var>)</code></pre> + +<h3 id="Parameter">Parameter</h3> + +<dl> + <dt><code>x</code></dt> + <dd>Eine Nummer.</dd> +</dl> + +<h3 id="Rückgabewert">Rückgabewert</h3> + +<p>Die Anzahl der führenden Nullbits in der 32-Bit binör Repräsentation der übergebenen Zahl.</p> + +<h2 id="Beschreibung">Beschreibung</h2> + +<p>"<code>clz32</code>" steht für <code>CountLeadingZeroes32 (<em>AnzahlFührenderNullen32</em>)</code>.</p> + +<p>Wenn <code>x</code> keine Nummer ist, wird <code>x</code> in eine Nummer konvertiert. Danach wird diese Nummer in einen 32-Bit vorzeichenlose Ganzzahl (unsigned integer) konvertiert.</p> + +<p>Wenn die konvertierte 32-Bit vorzeichenlose Zahl <code>0</code> ist, so wird die Funktion 32 zurück geben, weil alle Bits <code>0</code> sind.</p> + +<p>Diese Funktion ist nützlich für Systeme, die in zu JavaScript kompilieren (z. B. <a href="/en-US/docs/Emscripten">Emscripten</a>).</p> + +<h2 id="Beispiele">Beispiele</h2> + +<h3 id="Einsatz_von_Math.clz32()">Einsatz von <code>Math.clz32()</code></h3> + +<pre class="brush: js">Math.clz32(1); // 31 +Math.clz32(1000); // 22 +Math.clz32(); // 32 + +[NaN, Infinity, -Infinity, 0, -0, null, undefined, 'foo', {}, []].filter( +function(n) { + return Math.clz32(n) !== 32 +}); // [] + +Math.clz32(true); // 31 +Math.clz32(3.5); // 30 +</pre> + +<h2 id="Polyfill">Polyfill</h2> + +<p>Der folgende Polyfill ist der effizienteste.</p> + +<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">if</span> <span class="punctuation token">(</span><span class="operator token">!</span>Math<span class="punctuation token">.</span>clz32<span class="punctuation token">)</span> <span class="punctuation token">{</span> + Math<span class="punctuation token">.</span>clz32 <span class="operator token">=</span> <span class="keyword token">function</span><span class="punctuation token">(</span>x<span class="punctuation token">)</span> <span class="punctuation token">{</span> + <span class="comment token">// Let n be ToUint32(x).</span> + <span class="comment token">// Let p be the number of leading zero bits in </span> + <span class="comment token">// the 32-bit binary representation of n.</span> + <span class="comment token">// Return p. </span> + <span class="keyword token">if</span> <span class="punctuation token">(</span>x <span class="operator token">==</span> <span class="keyword token">null</span> <span class="operator token">||</span> x <span class="operator token">===</span> <span class="number token">0</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> + <span class="keyword token">return</span> <span class="number token">32</span><span class="punctuation token">;</span> + <span class="punctuation token">}</span> + <span class="keyword token">return</span> <span class="number token">31</span> <span class="operator token">-</span> Math<span class="punctuation token">.</span><span class="function token">floor</span><span class="punctuation token">(</span>Math<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>x <span class="operator token">></span><span class="operator token">></span><span class="operator token">></span> <span class="number token">0</span><span class="punctuation token">)</span> <span class="operator token">*</span> Math<span class="punctuation token">.</span>LOG2E<span class="punctuation token">)</span><span class="punctuation token">;</span> + <span class="punctuation token">}</span><span class="punctuation token">;</span> +<span class="punctuation token">}</span></code></pre> + +<h2 id="Spezifikationen">Spezifikationen</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES2015', '#sec-math.clz32', 'Math.clz32')}}</td> + <td>{{Spec2('ES2015')}}</td> + <td>Initiale Definition.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-math.clz32', 'Math.clz32')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browserkompatibilität">Browserkompatibilität</h2> + +<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> + +<p>{{Compat("javascript.builtins.Math.clz32")}}</p> + +<h2 id="Siehe_auch">Siehe auch</h2> + +<ul> + <li>{{jsxref("Math")}}</li> + <li>{{jsxref("Math.imul")}}</li> +</ul> |