Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<complex>: pow(complex<float>, int) returns complex<float> instead of complex<double> #325

Closed
amyw-msft opened this issue Nov 22, 2019 · 2 comments · Fixed by #383
Closed
Labels
bug Something isn't working fixed Something works now, yay!

Comments

@amyw-msft
Copy link
Member

amyw-msft commented Nov 22, 2019

The Standard states that pow(complex<float>, int) should treat both arguments as complex<double>, indicating that it should also return complex<double>. Instead it returns a complex<float>.

> type test.cpp

#include <complex>
#include <type_traits>

using namespace std;

int main()
{
    static_assert(
        is_same_v<
            complex<double>,
            decltype(pow(complex<float>{}, int{}))
        >,
        "pow(complex<float>, int) should return complex<double>"
        );
}

> cl /EHsc /nologo /W4 /std:c++17 test.cpp
test.cpp
test.cpp(12): error C2338: pow(complex<float>, int) should return complex<double>

WG21-N4835 [cmplx.over]/3 states:

Function template pow shall have additional overloads sufficient to ensure, for a call with at least one argument of type complex<T>:

  • If either argument has type complex<long double> or type long double, then both arguments are effectively cast to complex<long double>.
  • Otherwise, if either argument has type complex<double>, double, or an integer type, then both arguments are effectively cast to complex<double>.
  • Otherwise, if either argument has type complex<float> or float, then both arguments are effectively cast to complex<float>.

libc++ will return the correct type. libstdc++ will not. https://godbolt.org/z/_TscRV

Also tracked by Microsoft-internal VSO-177118.

@amyw-msft amyw-msft added the bug Something isn't working label Nov 22, 2019
Neargye added a commit to neargye-forks/STL that referenced this issue Dec 11, 2019
@Neargye
Copy link
Contributor

Neargye commented Dec 11, 2019

It's reproduced only when the int is on the right, because there is a special overload.

_NODISCARD complex<_Ty> pow(const complex<_Ty>& _Left, int _Right) {

@Neargye
Copy link
Contributor

Neargye commented Dec 11, 2019

Try to fix during #383

Neargye added a commit to neargye-forks/STL that referenced this issue Dec 12, 2019
@Neargye Neargye mentioned this issue Dec 12, 2019
5 tasks
Neargye added a commit to neargye-forks/STL that referenced this issue Dec 15, 2019
Neargye added a commit to neargye-forks/STL that referenced this issue Dec 16, 2019
Neargye added a commit to neargye-forks/STL that referenced this issue Dec 16, 2019
Neargye added a commit to neargye-forks/STL that referenced this issue Jan 22, 2020
StephanTLavavej pushed a commit that referenced this issue Jan 24, 2020
@StephanTLavavej StephanTLavavej added fixed Something works now, yay! and removed work in progress labels Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants