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

后端 未结 2 1682
醉话见心
醉话见心 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:37

    As Fred Larson correctly points out the documentation says:

    The result of pow(0, 0) is implementation-defined.

    Mathematically this makes sense since we have a contradictory situation where N^0 should always be 1 but 0^N should always be 0 for N > 0, so you should have no expectations mathematically as to the result of this either. This Wolfram Alpha forum posts goes into a bit more details.

    The case where the imaginary portion of the complex number is not zero is more complex situation. If the x in x^y is real then it should also be undefined but if x has an imaginary component then it looks like it is no longer undefined.

提交回复
热议问题