为什么(0 + 0i)^ {0} ==(nan,nan)在c ++ [英] why (0+0i)^{0} == (nan, nan) in c++

查看:171
本文介绍了为什么(0 + 0i)^ {0} ==(nan,nan)在c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看代码blew:

#include <complex>
#include <iostream>

int main()
{
    std::cout << std::pow( std::complex<double>(0,0), std::complex<double>(0,0) ) << "\n";
    std::cout << std::pow( std::complex<double>(0,0), double(0) ) << "\n";

    return 0;
}

g ++(4.8.1)输出

g++(4.8.1) gives an output of

(nan,nan)
(-nan,-nan)

而clang ++(3.3)给出输出

while clang++(3.3) gives an out put of

(-nan,-nan)
(-nan,-nan)

推荐答案

根据 std :: pow文档

返回值

由幂(exp或iexp)引起的基数。

发生域错误 if base是0,exp小于或等于0. 在这种情况下返回NAN。
[...]

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. [...]

在你的代码中,两个基数都为0,exp等于0, 0 + 0 * i 仍为0.所以 NaN 似乎是预期的。

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.

由@Fred Larson提供,并根据 overloaded std :: pow for std: :complex

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


计算复杂乘数x。该操作被定义为exp(y·log(x))。沿着负实轴存在分支切口。
pow(0,0)的结果是实现定义的

这篇关于为什么(0 + 0i)^ {0} ==(nan,nan)在c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆