Describe the bug
I'm trying to do some simple phase calculations in C++ and discovered that I was sometimes getting the wrong results from std::arg when using real values as input.
According to the documentation on cppreference:
Additional overloads are provided for float, double, long double, and all integer types, which are treated as complex numbers with zero imaginary component.
However this does not seem to be the case, because these two calls return different results.
auto x1 = std::arg(std::complex<double>{ -1.0, 0.0 });
// x1 = PI (3.14159...)
auto x2 = std::arg(-1.0);
// x2 = 0
Command-line test case
#include <complex>
#include <iostream>
int main() {
auto x1 = std::arg(std::complex<double>{ -1.0, 0.0 });
auto x2 = std::arg(-1.0);
if (x1 != x2)
{
std::cout << "test failure" << std::endl;
}
}
Expected behavior
I would expect std::arg to function as described in the documentation. When passed a real value as an input it should act the same as if it were passed a complex value with a zero imaginary component.
STL version
Microsoft Visual Studio Community 2019 Preview
Version 16.6.0 Preview 5.0
Additional Context
Looking at the source code it looks like when passed a real value std::arg is hardcoded to just return 0.
Yep, this is a bug - thanks for the perfect bug report!
https://github.com/microsoft/STL/blob/2f4c5792b2be4f56b4130817803ca21f7a3ee8f4/stl/inc/complex#L1684-L1687
https://github.com/microsoft/STL/blob/2f4c5792b2be4f56b4130817803ca21f7a3ee8f4/stl/inc/complex#L1760-L1763
I'll try to get a fix in for VS 2019 16.7 Preview 2.
There were so many bugs in these overloads 馃檧 (as @CaseyCarter noticed) but I'm fixing them all 馃樃
Thanks again for reporting this bug! The fix will indeed ship in VS 2019 16.7 Preview 2.
Awesome! Thanks for the super quick turnaround! :)
For the record, this was also tracked by DevCom-125537 and Microsoft-internal VSO-507908.