JS中的Math.pow(a,b)方法


定義和用法
pow() 方法可返回 x 的 y 次冪的值。
語法 Math.pow(x,y)
參數 描述 x 必需。底數。必須是數字。 y 必需。冪數。必須是數字。
返回值 x 的 y 次冪。
說明 如果結果是虛數或負數,則該方法將返回 NaN。如果由於指數過大而引起浮點溢出,則該方法將返回 Infinity。
實例 在下面的例子中,我們將把 pow() 運用到不同的數字組合上:
<script type="text/javascript"> document.write(Math.pow(0,0) + "<br />") document.write(Math.pow(0,1) + "<br />") document.write(Math.pow(1,1) + "<br />") document.write(Math.pow(1,10) + "<br />") document.write(Math.pow(2,3) + "<br />") document.write(Math.pow(-2,3) + "<br />") document.write(Math.pow(2,4) + "<br />") document.write(Math.pow(-2,4) + "<br />") </script> 輸出: 1 0 1 1 8 -8 16 16

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM