javascript怎么进行求幂运算
时间:2022-02-16 16:43
javascript进行求幂运算的方法:1、利用Math对象的pow()方法,语法“Math.pow(n, m)”,可返回n的m次幂的值;2、利用求幂运算符“**”,语法“x ** y”,可返回x的y次幂的值。 本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。 求幂运算 幂(power)是指数运算的结果。当m为正整数时,nᵐ指该式意义为m个n相乘。当m为小数时,m可以写成a/b(其中a、b为整数),nᵐ表示nᵃ再开b次根号。 当m为虚数时,则需要利用欧拉公式 eiθ=cosθ+isinθ,再利用对数性质求解。 把nᵐ看作乘方的结果,叫做n的m次幂,也叫n的m次方。 javascript怎么进行求幂运算 方法1:使用pow()方法 pow() 方法可返回 n 的 m 次幂 (nᵐ) 的值。如果结果是虚数或负数,则该方法将返回 NaN。如果由于指数过大而引起浮点溢出,则该方法将返回 Infinity。 示例:返回 4 的 3 次幂 (4*4*4) 的值 方法2:使用求幂运算符( 求幂运算符(**)返回第一个操作数做底数,第二个操作数做指数的乘方。它等效于 【相关推荐:javascript学习教程】 以上就是javascript怎么进行求幂运算的详细内容,更多请关注gxlsystem.com其它相关文章!console.log(Math.pow(4, 3));
**
)Math.pow
,不同之处在于它也接受BigInts作为操作数。console.log(3 ** 4);
// expected output: 81
console.log(10 ** -2);
// expected output: 0.01
console.log(2 ** 3 ** 2);
// expected output: 512
console.log((2 ** 3) ** 2);
// expected output: 64