gpt4 book ai didi

javascript - 是否有 Math.pow(x, 0) 不为 1 的 `x` 值?

转载 作者:搜寻专家 更新时间:2023-11-01 00:09:58 25 4
gpt4 key购买 nike

我在 previous question 中找到了Math.pow(0, 0) === 1 返回 true

the documentation我们发现 x^y 的以下规则:

  • If y is NaN, the result is NaN.
  • If y is +0, the result is 1, even if x is NaN.
  • If y is −0, the result is 1, even if x is NaN.
  • If x is NaN and y is nonzero, the result is NaN.
  • If abs(x)>1 and y is +∞, the result is +∞.
  • If abs(x)>1 and y is −∞, the result is +0.
  • If abs(x)==1 and y is +∞, the result is NaN.
  • If abs(x)==1 and y is −∞, the result is NaN.
  • If abs(x)<1 and y is +∞, the result is +0.
  • If abs(x)<1 and y is −∞, the result is +∞.
  • If x is +∞ and y>0, the result is +∞.
  • If x is +∞ and y<0, the result is +0.
  • If x is −∞ and y>0 and y is an odd integer, the result is −∞.
  • If x is −∞ and y>0 and y is not an odd integer, the result is +∞.
  • If x is −∞ and y<0 and y is an odd integer, the result is −0.
  • If x is −∞ and y<0 and y is not an odd integer, the result is +0.
  • If x is +0 and y>0, the result is +0.
  • If x is +0 and y<0, the result is +∞.
  • If x is −0 and y>0 and y is an odd integer, the result is −0.
  • If x is −0 and y>0 and y is not an odd integer, the result is +0.
  • If x is −0 and y<0 and y is an odd integer, the result is −∞.
  • If x is −0 and y<0 and y is not an odd integer, the result is +∞.
  • If x<0 and x is finite and y is finite and y is not an integer, the result is NaN.

有趣的是,对于 x 的任何值,返回的值为 1。我们能否找到 x 的任何值,因为 Math.pow(x, 0) 返回的值不是 1

我在 NodeJS shell 中尝试了以下操作,但我猜它在浏览器控制台中的结果是一样的:

> Math.pow(undefined, 0)
1
> Math.pow(Date(), 0)
1
> Math.pow("asd", 0)
1
> Math.pow(function () {}, 0)
1
> Math.pow(function () { return 3}, 0)
1
> Math.pow([], 0)
1
> Math.pow(null, 0)
1

也许我们找到了执行此操作的 JS 技巧,例如 x === x // false (where isNaN(x) === false)案例。


澄清一下:y 将始终为 0。只有 x 发生了变化。

最佳答案

您从文档中复制/粘贴的内容包括以下要求:

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

所以你的问题的答案似乎是“否”

关于javascript - 是否有 Math.pow(x, 0) 不为 1 的 `x` 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19976978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com