Why is Math.pow(0, 0) === 1?

后端 未结 9 751
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 01:47

We all know that 00 is indeterminate.

But, javascript says that:

Math.pow(0, 0) === 1 // true

9条回答
  •  孤街浪徒
    2020-11-30 02:21

    According to Wikipedia:

    In most settings not involving continuity in the exponent, interpreting 00 as 1 simplifies formulas and eliminates the need for special cases in theorems.

    There are several possible ways to treat 0**0 with pros and cons to each (see Wikipedia for an extended discussion).

    The IEEE 754-2008 floating point standard recommends three different functions:

    • pow treats 0**0 as 1. This is the oldest defined version. If the power is an exact integer the result is the same as for pown, otherwise the result is as for powr (except for some exceptional cases).
    • pown treats 0**0 as 1. The power must be an exact integer. The value is defined for negative bases; e.g., pown(−3,5) is −243.
    • powr treats 0**0 as NaN (Not-a-Number – undefined). The value is also NaN for cases like powr(−3,2) where the base is less than zero. The value is defined by exp(power'×log(base)).

提交回复
热议问题