最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Math.pow and Infinity - Stack Overflow

programmeradmin4浏览0评论

There are seven indeterminate forms in maths. Most of them returns NaN in JavaScript. But when i try:

Math.pow( 0, 0 )

or

Math.pow( Infinity, 0 )

it returns:

1

Is this some kind of bug?

There are seven indeterminate forms in maths. Most of them returns NaN in JavaScript. But when i try:

Math.pow( 0, 0 )

or

Math.pow( Infinity, 0 )

it returns:

1

Is this some kind of bug?

Share Improve this question asked Mar 8, 2012 at 9:37 HahiHahi 12110 bronze badges 1
  • 2 everything to the power of 0 is one - askamathematician./2010/12/… – scibuff Commented Mar 8, 2012 at 9:40
Add a ment  | 

3 Answers 3

Reset to default 5

That's what the specification says, so it's not a bug:

2. If y is +0, the result is 1, even if x is NaN.

No, because anything to the power of zero is one.

Not only is this easier to implement, it is mathematically correct (some mathematicians say pow(0, 0) is undefined, but general convention is to take pow(x, 0) == 1 for any x).

On top of that it is in the specification (link officialy stolen from primvdb): http://es5.github./#x15.8.2.13

No, it is not a bug. This behaviour is pliance with the ECMA definition of Javascript.

发布评论

评论列表(0)

  1. 暂无评论