c++ - Intel icpc and C++14: How to constexpr std::complex? -


in calculations use imaginary unit , think compiler should able simplify these operations @ compile time reducing things like

a + b --> std::complex(a,b) 

of course above simplified , expressions more complex (pun intended).

in c++14 can use complex literals that, whereas in c++11 using constexpr std::complex variable. however, both of these methods fail intel c++ compiler icpc error messages comments in source.

how can work around these glitches?

#include <complex>  auto test1(double a, double b) {   // error #1909: complex integral types not supported   using namespace std::complex_literals;   auto z = + 1i*b;   return z; }  auto test2(double a, double b) {   // error: calling default constructor "std::complex<double>" not produce constant value   constexpr std::complex<double> i(0,1);   auto z = + i*b;   return z; }  auto test3(double a, double b) {   // can optimized others?   std::complex<double> i(0,1);   auto z = + i*b;   return z; } 

bonus question: why test2 optimized away , replaced jump test3? (see https://godbolt.org/g/pw1jz8)

the error on complex literals self-explanatory. version of intel compiler got handy (16.0.3) neither supports them.

when comes second error, i'd depends on gcc standard library version using, because icpc not ship (complete) standard library. have installed gcc 5.4 , test2 function compiles correctly.

what should make difference whether constructor of std::complex anotated constexpr. in gcc 5.4 is:

       _glibcxx_constexpr complex(const _tp& __r = _tp(), const _tp& __i = _tp())   : _m_real(__r), _m_imag(__i) { } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -