D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17173 - Incorrect return value for function accepting and returning cdouble
Summary: Incorrect return value for function accepting and returning cdouble
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Mac OS X
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-10 14:56 UTC by Sophie
Modified: 2022-11-16 14:42 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Sophie 2017-02-10 14:56:41 UTC
This code behaves correctly when compiling with DMD v2.072.0 on Win7. It behaves incorrectly with the same DMD version on OSX.

    import std.stdio;

    auto fn(in cdouble value){
        writeln(value.re + 0i); // Prints 64+0i
        return value.re + 0i;
    }

    unittest{
        writeln(fn(64 + 0i)); // Prints 64+64i, should print 64+0i
    }

It behaves correctly if:

If writeln is removed from fn (In the case where I encountered this bug, there was other essential code but no writeln, I don't think this is related to writeln specifically)

If an empty out contract is added to fn
Comment 1 RazvanN 2022-11-16 14:42:12 UTC
I cannot reproduce this. Firstly, cdouble is deprecated so std.complex.Complex should be used instead. Secondly, both using cdouble and Complex the result is 64+0i in both prints.

Closing as WORKSFORME.