英文:
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+1j
或 0+0j
),std::arg
将按照这些参数上 std::atan2
的结果来计算。
<details>
<summary>英文:</summary>
[[complex.value.ops]p4](https://wg21.link/complex.value.ops#4):
> ```c++
> template<class T> T arg(const complex<T>& x);
> ```
> *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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论