Open amyw-msft opened 3 years ago
I've investigated this issue and it is not related to complex numbers. It is related to double precision and parsing a double number.
On hex representation of values you can see, that the difference between wolfram value and STL value is just one bit. Actual value for real part in first test is 0.4283501361292150480680021695357 (which is returned by wolfram), but when it was converted to double from string it became 0.428350136129215075531107004281, but it is not closest approximation to real value (probably because it just run out of precise significant digits and gave up parsing on ...4806...), but when it was calculated as cosine (when real part is 0 it simplifies to cos(imag)) of double value (which was precise double representation) it gets closer approximation of 0.428350136129215020019955773023.
All in all it is not a bug of complex, it is just question of double precision (which is related to atof() function implementation in UCRT library)
Bug Description When using std::complex, results may be off by 1 ULP.
Command-line test case Note: This test case also compares against what the user reported the Fortran result was.
amd64:
x86:
Expected behavior Our results should agree with results from Wolfram Alpha (which is also what is returned by libstdc++ and libc++)
STL version
Additional context This affects the UCRT (MSFT-31014699) as well, which has a different implementation that agrees with MSVC STL. Also tracked by DevCom-1271319 and Microsoft-internal VSO-1255553.