Math.pow with negative numbers and non-integer powers

后端 未结 2 1915
予麋鹿
予麋鹿 2020-12-10 05:02

The ECMAScript specification for Math.pow has the following peculiar rule:

  • If x < 0 and x is finite and y is finite and y is n
2条回答
  •  时光说笑
    2020-12-10 05:55

    I assume because those circumstances lead the result into complex waters, and ECMAScript is not equipped with imaginary numbers. Specifically, your example should result in something close to 1 + 1.732i, among other results. (The fact that -2 is also a possible result is besides the point - it is an accident rather than a rule.)

提交回复
热议问题