https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61795

            Bug ID: 61795
           Summary: [C++11] return type of std::pow(std::complex<float>,
                    int) should be std::complex<double>
           Product: gcc
           Version: 4.10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kariya_mitsuru at hotmail dot com

With libstdc++, the return type of std::pow(std::complex<float>, int) is
std::complex<float>.
However, In C++11 mode, the return type of std::pow(std::complex<float>, int)
should be std::complex<double>.


According to C++11 standard 26.4.9[cmplx.over] paragraph 3, "if either argument
has type complex<double>, double, or an integer type, then both arguments are
effectively cast to complex<double>."

The return type of std::pow(std::complex<double>, std::complex<double>) is
std::complex<double>, So I think that std::pow(std::complex<float>, int) should
be std::complex<double> in C++11 mode.


The sample code below can show whether the return type is std::complex<double>.
================================================================================
#include <iostream>
#include <typeinfo>
#include <complex>

int main()
{
  std::cout << std::boolalpha
            << (typeid(std::pow(std::complex<float>(1), 1)) ==
typeid(std::complex<double>))
            << std::endl;
}
================================================================================
cf. http://melpon.org/wandbox/permlink/zW8TWZe9kKzKWqFq


While in C++03 mode, the return type of std::pow(std::complex<float>, int)
should be std::complex<float>, I think.

Note that this problem does not occur in std::complex<double> and
std::complex<long double> because there is no difference between C++03 and
C++11.


See also: PR56106, PR57974

Reply via email to