Compiling C code in Visual Studio 2013 with complex.h library

后端 未结 2 1896
逝去的感伤
逝去的感伤 2020-12-06 06:55

http://blogs.msdn.com/b/vcblog/archive/2013/07/19/c99-library-support-in-visual-studio-2013.aspx

C99 support added visual studio 2013, but I cant use complex.h in my

相关标签:
2条回答
  • 2020-12-06 07:03

    In case anyone is searching a year later, try

    _Dcomplex dc1 = {3.0, 2.0};

    for the variable declaration.

    From looking inside VS2013's "complex.h" header, it seems that Microsoft decided on their own implementation for C complex numbers. You'll have to implement your own arithmetical operators using the real() and imag() functions, i.e.:

    double real_part = real(dc1) + real(dc2);
    double imag_part = imag(dc1) + imag(dc2);
    _Dcomplex result = {real_part, imag_part};
    
    0 讨论(0)
  • 2020-12-06 07:15

    Another way is to define like:

    /*_Fcomplex */  _C_float_complex a =  _FCbuild(5.0F, 1.0F);    
    printf( "z = %.1f% + .1fi\n", crealf(a), cimagf(a));    
    
    /*_Dcomplex*/ _C_double_complex b = _Cbuild(3.0, 2.0);    
    printf("z = %.1f% + .1fi\n",creal(b), cimag(b));    
    
    0 讨论(0)
提交回复
热议问题