why (0+0i)^{0} == (nan, nan) in c++

后端 未结 2 1687
醉话见心
醉话见心 2021-01-04 16:04

take a look at the code blew:

#include 
#include 

int main()
{
    std::cout << std::pow( std::complex(0,         


        
2条回答
  •  清歌不尽
    2021-01-04 16:44

    According to std::pow documentation

    Return value
    base raised by power (exp or iexp).
    Domain error occurs if base is 0 and exp is less than or equal to ​0​. NAN is returned in that case. [...]

    In your code, you have both base with 0 and exp equal to 0 since the complex number 0 + 0 *i is still 0. So NaN seems expected.

    By courtesy of @Fred Larson, and according to overloaded std::pow for std::complex

    Computes complex x raised to a complex power y. The operation is defined as exp(y · log(x) ). A branch cut exists along the negative real axis. The result of pow(0, 0) is implementation-defined.

提交回复
热议问题