Bug 17173 – Incorrect return value for function accepting and returning cdouble
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2017-02-10T14:56:41Z
Last change time
2022-11-16T14:42:12Z
Assigned to
No Owner
Creator
Sophie
Comments
Comment #0 by meapineapple — 2017-02-10T14:56:41Z
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 by razvan.nitu1305 — 2022-11-16T14:42:12Z
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.