vendredi 26 août 2016

Why don't complex-number literals work in clang?

When I run this code on ideone.com, it prints (2,3):

#include <iostream>
#include <complex>

int main() {
    std::complex<double> val = 2 + 3i;
    std::cout << val << std::endl;
    return 0;
}

But when I use clang on macOS 10.11.6, I get no errors or warnings, but the output is (2,0):

$ clang --version
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0

$ clang -lc++ test.cpp && ./a.out
(2,0)

What happened to the imaginary part? Am I doing something wrong?

Aucun commentaire:

Enregistrer un commentaire