Math.pow() - JavaScript 编辑
The Math.pow()
function returns the base
to the exponent
power, that is, baseexponent
.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.Syntax
Math.pow(base, exponent)
Parameters
base
- The base number.
exponent
- The exponent used to raise the
base
.
Return value
A number representing the given base taken to the power of the given exponent.
Description
The Math.pow()
function returns the base
to the exponent
power, that is, baseexponent
, the base
and the exponent
are in decimal numeral system.
Because pow()
is a static method of Math
, you always use it as Math.pow()
, rather than as a method of a Math
object you created (Math
has no constructor). If the base is negative and the exponent is not an integer, the result is NaN.
Examples
Using Math.pow()
// simple
Math.pow(7, 2); // 49
Math.pow(7, 3); // 343
Math.pow(2, 10); // 1024
// fractional exponents
Math.pow(4, 0.5); // 2 (square root of 4)
Math.pow(8, 1/3); // 2 (cube root of 8)
Math.pow(2, 0.5); // 1.4142135623730951 (square root of 2)
Math.pow(2, 1/3); // 1.2599210498948732 (cube root of 2)
// signed exponents
Math.pow(7, -2); // 0.02040816326530612 (1/49)
Math.pow(8, -1/3); // 0.5
// signed bases
Math.pow(-7, 2); // 49 (squares are positive)
Math.pow(-7, 3); // -343 (cubes can be negative)
Math.pow(-7, 0.5); // NaN (negative numbers don't have a real square root)
// due to "even" and "odd" roots laying close to each other,
// and limits in the floating number precision,
// negative bases with fractional exponents always return NaN
Math.pow(-7, 1/3); // NaN
Specifications
Specification |
---|
ECMAScript (ECMA-262) The definition of 'Math.pow' in that specification. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论