Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

Implicit conversions for std::complex

$
0
0

Passing a std::complex<float> constant to a function that takes a std::complex<double> argument receives the wrong real part inside the function.    Passing a std::complex variable produces the expected result.   Changing the function to accept a value rather than a const reference makes no difference.

#include <complex>
#include <iostream>

void f(const std::complex<double> &val)   // or void f(std::complex<double> val)
{
    std::cout << "In f1, val = "<< val << std::endl;
}

int main()
{

    f(std::complex<float>(1,2));   // Fails

    std::complex<float> b(1,2);
    f(b);  // Works
    

    return 0;
}

Produces the output:

In f1, val = (2,2)
In f1, val = (1,2)

 

This is with the Intel compiler 19.0.4.243.    GCC and clang give the expected results.

 


Viewing all articles
Browse latest Browse all 1175

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>