首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::sqrt(std::complex)

Defined in header <complex>

?

?

template< class T > complex<T> sqrt( const complex<T>& z );

?

?

计算复数的平方根。z在负实轴上有一个分支。

参数

z

-

complex number to take the square root of

返回值

如果没有发生错误,则返回z,在右半平面的范围内,包括虚轴%28。[0;+∞%29沿实轴,%28-∞;+∞%29沿虚轴。%29。

如果这个论点是一个负实数,则结果是在正虚轴上。

错误处理和特殊值

错误报告与math_errhandling...

如果实现支持ieee浮点算法,

  • 考虑到虚部的符号,该函数连续于分支割集上。
  • std::sqrt(std::conj(z))== std::conj(std::sqrt(z))
  • 如果z(±0,+0),结果是(+0,+0)
  • 如果z(x,+∞),结果是(+∞,+∞)即使x是NaN
  • 如果z(x,NaN),结果是(NaN,NaN)%28,除非x是±∞%29和FE_INVALID可能被提高
  • 如果z(-∞,y),结果是(+0,+∞)对于有限正y
  • 如果z(+∞,y),结果是(+∞,+0)对于有限正y
  • 如果z(-∞,NaN),结果是(NaN,∞)%28虚设部分符号未指定%29
  • 如果z(+∞,NaN),结果是(+∞,NaN)
  • 如果z(NaN,y),结果是(NaN,NaN)FE_INVALID可能被提高
  • 如果z(NaN,NaN),结果是(NaN,NaN)

二次

代码语言:javascript
复制
#include <iostream>
#include <complex>
 
int main()
{
    std::cout << "Square root of -4 is "
              << std::sqrt(std::complex<double>(-4, 0)) << '\n'
              << "Square root of (-4,-0), the other side of the cut, is "
              << std::sqrt(std::complex<double>(-4, -0.0)) << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
Square root of -4 is (0,2)
Square root of (-4,-0), the other side of the cut, is (0,-2)

二次

另见

pow(std::complex)

complex power, one or both arguments may be a complex number (function template)

sqrt

computes square root (√x) (function)

sqrt(std::valarray)

applies the function std::sqrt to each element of valarray (function template)

c csqrt文档

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com