This forum has been archived. All content is frozen. Please use KDE Discuss instead.

multiplication with i

Tags: None
(comma "," separated)
foo
Registered Member
Posts
1
Karma
0

multiplication with i

Thu Mar 02, 2017 7:40 pm
Code: Select all
#include <Eigen/core>
#include <iostream>
#include <complex>

int main(){
    Eigen::Matrix2cd test;
    test<<0.0 + 1.0j, 2.0 + 3.0j, 4.0 + 5.0j, 6.0 + 7.0j;
    test = test * 1.0j;
    std::cout<<test<<std::endl;
}


outputs a zero matrix in Eigen 3.3, and the correct one in Eigen 3.2. However, using

Code: Select all
#include <Eigen/core>
#include <iostream>
#include <complex>

int main(){
    Eigen::Matrix2cd test;
    test<<0.0 + 1.0j, 2.0 + 3.0j, 4.0 + 5.0j, 6.0 + 7.0j;
    test = test * std::complex<double>(0.0, 1.0);
    std::cout<<test<<std::endl;
}

works fine. Took me a while to hunt this down. Is this a bug or on purpose?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: multiplication with i

Tue Mar 07, 2017 9:31 am
hm, your examples are invalid, j instead of i, and you need to include the std::complex_literals namespace. The following example work fine with either 3.2 or 3.3:

Code: Select all
#include <Eigen/core>
#include <iostream>

using namespace std::complex_literals;

int main(){
    Eigen::Matrix2cd test;
    test<<0.0 + 1.0i, 2.0 + 3.0i, 4.0 + 5.0i, 6.0 + 7.0i;
    std::cout<<test<<std::endl;
    test = test * 1.0i;
    std::cout<<test<<std::endl;
}


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]