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

后端 未结 9 690
伪装坚强ぢ
伪装坚强ぢ 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:13

    The C language definition says (7.12.7.4/2):

    A domain error may occur if x is zero and y is zero.

    It also says (7.12.1/2):

    On a domain error, the function returns an implementation-defined value; if the integer expression math_errhandling & MATH_ERRNO is nonzero, the integer expression errno acquires the value EDOM; if the integer expression math_errhandling & MATH_ERREXCEPT is nonzero, the ‘‘invalid’’ floating-point exception is raised.

    By default, the value of math_errhandling is MATH_ERRNO, so check errno for the value EDOM.

提交回复
热议问题