mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-10 07:54:06 +08:00
92 lines
3.5 KiB
HTML
92 lines
3.5 KiB
HTML
<article id="wikiArticle">
|
||
<div></div>
|
||
<h2 id="Summary" name="Summary">概述</h2>
|
||
<p>该函数返回两个参数的类C的32位整数乘法运算的运算结果.</p>
|
||
<h2 id="语法">语法</h2>
|
||
<pre><code class="language-javascript"><code>Math.imul(a, b)</code></code></pre>
|
||
<h3 id="Parameters" name="Parameters">参数</h3>
|
||
<dl>
|
||
<dt><code>a</code></dt>
|
||
<dd>被乘数.</dd>
|
||
<dt><code>b</code></dt>
|
||
<dd>乘数.</dd>
|
||
</dl>
|
||
<h2 id="描述">描述</h2>
|
||
<p><code>Math.imul</code>可以进行快速的,类C语义的32位整数乘法.该特性对于一些项目比如<a class="external" href="http://en.wikipedia.org/wiki/Emscripten" rel="noopener" title="http://en.wikipedia.org/wiki/Emscripten">Emscripten</a>很有用.</p>
|
||
<h2 id="例子">例子</h2>
|
||
<pre><code class="language-javascript">Math.imul(2, 4) // 8
|
||
Math.imul(-1, 8) // -8
|
||
Math.imul(-2, -2) // 4
|
||
Math.imul(0xffffffff, 5) //-5
|
||
Math.imul(0xfffffffe, 5) //-10
|
||
</code></pre>
|
||
<h2 id="Polyfill">Polyfill</h2>
|
||
<p>下面的JavaScript代码可以实现该函数:</p>
|
||
<pre><code class="language-javascript">function imul(a, b)
|
||
{
|
||
var ah = (a >>> 16) & 0xffff;
|
||
var al = a & 0xffff;
|
||
var bh = (b >>> 16) & 0xffff;
|
||
var bl = b & 0xffff;
|
||
// 右移0位可以修复高位的符号位
|
||
return (al * bl) + (((ah*bl+al*bh)<<16)>>>0);
|
||
}
|
||
</code></pre>
|
||
<h2 id="浏览器兼容性">浏览器兼容性</h2>
|
||
<p></p><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
|
||
This compatibility table still uses the old format,
|
||
because we haven't yet converted the data it contains.
|
||
<strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
|
||
<div class="htab">
|
||
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
|
||
<ul>
|
||
<li class="selected"><a>Desktop</a></li>
|
||
<li><a>Mobile</a></li>
|
||
</ul>
|
||
</div><p></p>
|
||
<div id="compat-desktop">
|
||
<table class="compat-table">
|
||
<tbody>
|
||
<tr>
|
||
<th>Feature</th>
|
||
<th>Firefox (Gecko)</th>
|
||
<th>Chrome</th>
|
||
<th>Internet Explorer</th>
|
||
<th>Opera</th>
|
||
<th>Safari</th>
|
||
</tr>
|
||
<tr>
|
||
<td>Basic support</td>
|
||
<td><a href="/en-US/Firefox/Releases/20" title="Released on 2013-04-02.">20</a> (20)</td>
|
||
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div id="compat-mobile">
|
||
<table class="compat-table">
|
||
<tbody>
|
||
<tr>
|
||
<th>Feature</th>
|
||
<th>Firefox Mobile (Gecko)</th>
|
||
<th>Android</th>
|
||
<th>IE Mobile</th>
|
||
<th>Opera Mobile</th>
|
||
<th>Safari Mobile</th>
|
||
</tr>
|
||
<tr>
|
||
<td>Basic support</td>
|
||
<td>20.0 (20)</td>
|
||
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p> </p>
|
||
</article> |