www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20688] New: Wrong code when linking to C complex number

https://issues.dlang.org/show_bug.cgi?id=20688

          Issue ID: 20688
           Summary: Wrong code when linking to C complex number functions
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

C program:

/////////////////// test.c ///////////////////
#include <stdio.h>
#include <complex.h>

int main()
{
    double complex r = cpow(2 + 0*I, 2 + 0*I);
    printf("%f+%fi\n", creal(r), cimag(r));
    return 0;
}
//////////////////////////////////////////////

As expected, this prints 4.000000+0.000000i.

Equivalent D program:

////////////////// test.d /////////////////
import std.stdio;

import core.stdc.complex;

void main()
{
    cdouble r = cpowf(2. + 0i, 2. + 0i);
    printf("%f+%fi\n", creal(r), cimag(r));
}
///////////////////////////////////////////

This prints garbage (for me, randomly -0.000000+-0.000000i or nan+nani).

--
Mar 19