argf和atan2f在C++中有什么区别?

huangapple go评论71阅读模式
英文:

What is the Difference Between argf and atan2f in C++?

问题

我正在使用FFT数学进行项目开发,在某些情况下需要计算实部和虚部FFT分量的相位角度。在一些示例中,我看到人们使用atan2f来执行此操作,而在其他示例中,人们与复数类一起使用argf。

除了接受两个单独参数与接受一个复数参数之外,这两个函数的操作方式是否有任何区别?如果有,具体的区别是什么?

我一直在各种在线文档中搜索,似乎找不到清晰或简明的答案。

谢谢!

这个信息源特别令人困惑:

如果没有发生错误,返回z在区间[-π; π]内的相位角度。
错误和特殊情况会被处理,就好像函数实现为std::atan2(std::imag(z), std::real(z))一样。

这并不清楚它们是否在所有情况下等效,还是只有在存在边界情况或错误时才等效。

英文:

I am working on a project using FFT math, running into a situation where I need to calculate the phase angle of the real and imaginary FFT components. In some examples I see people using atan2f to do this, and in some I see people using argf alongside the complex number class.

Is there any difference in the way these two functions operate other than taking two separate arguments versus a single complex number argument? If so, what is the difference?

Have been scouring various documentation online and can't seem to find a clear or concise answer to this question.

Thanks!

This source was particularly confusing:

> If no errors occur, returns the phase angle of z in the interval [−π; π].
> Errors and special cases are handled as if the function is implemented as std::atan2(std::imag(z), std::real(z)).

This isn't clear whether they are equivalent in all cases, or only when there is an edge case or an error.

答案1

得分: 5

template<class T> T arg(const complex<T>& x);

返回: x的相位角,或atan2(imag(x), real(x))

没有区别,std::arg(std::complex(x, y)) 等同于 std::atan2(y, x)

如果您的复数没有相位角(例如,NaN+1j0+0j),std::arg 将按照这些参数上 std::atan2 的结果来计算。


<details>
<summary>英文:</summary>

[[complex.value.ops]p4](https://wg21.link/complex.value.ops#4):

&gt; ```c++
&gt; template&lt;class T&gt; T arg(const complex&lt;T&gt;&amp; x);
&gt; ```
&gt; *Returns*: The phase angle of `x`, or `atan2(imag(x), real(x))`.

There is no difference, `std::arg(std::complex(x, y))` is `std::atan2(y, x)`.

If your complex number happens to not have a phase (e.g, `NaN+1j` or `0+0j`), `std::arg` will follow the results of `std::atan2` on those arguments.

</details>



huangapple
  • 本文由 发表于 2023年7月14日 04:31:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76683050.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定