Thread overview
Using shorthand *= leads to unexpected result?
May 15, 2016
Michael
May 15, 2016
Saurabh Das
May 15, 2016
Michael
May 15, 2016
Saurabh Das
May 15, 2016
Marc Schütz
May 15, 2016
Michael
May 15, 2016
It may be that I'm doing something wrong here, but after updating DMD to the latest version, my simulations started producing some very odd results and I think I've pinpointed it to a sign inversion that I was making. Here is some code from dpaste to demonstrate the behaviour I get vs. the behaviour I expected:
https://dpaste.dzfl.pl/9bd7aea75fb2

Any ideas? Am I getting something wrong or is this some sort of regression with the latest DMD?
May 15, 2016
On Sunday, 15 May 2016 at 13:01:45 UTC, Michael wrote:
> It may be that I'm doing something wrong here, but after updating DMD to the latest version, my simulations started producing some very odd results and I think I've pinpointed it to a sign inversion that I was making. Here is some code from dpaste to demonstrate the behaviour I get vs. the behaviour I expected:
> https://dpaste.dzfl.pl/9bd7aea75fb2
>
> Any ideas? Am I getting something wrong or is this some sort of regression with the latest DMD?

Strangely, if I substitute the variable type 'auto' for 'float' or 'real', it gives the expected output of -1. Variable type 'double' gives the incorrect value of 1.

This is strange behaviour. Perhaps someone more knowledgeable can shed light. If it is a regression, it is a very serious regression :(

~ sd

May 15, 2016
On Sunday, 15 May 2016 at 13:12:44 UTC, Saurabh Das wrote:
> On Sunday, 15 May 2016 at 13:01:45 UTC, Michael wrote:
>> It may be that I'm doing something wrong here, but after updating DMD to the latest version, my simulations started producing some very odd results and I think I've pinpointed it to a sign inversion that I was making. Here is some code from dpaste to demonstrate the behaviour I get vs. the behaviour I expected:
>> https://dpaste.dzfl.pl/9bd7aea75fb2
>>
>> Any ideas? Am I getting something wrong or is this some sort of regression with the latest DMD?
>
> Strangely, if I substitute the variable type 'auto' for 'float' or 'real', it gives the expected output of -1. Variable type 'double' gives the incorrect value of 1.
>
> This is strange behaviour. Perhaps someone more knowledgeable can shed light. If it is a regression, it is a very serious regression :(
>
> ~ sd

Well I'm pretty sure the code was working just fine earlier in the week at the office, but running the code at home with the newest version of DMD started producing these odd results.
May 15, 2016
On Sunday, 15 May 2016 at 13:25:42 UTC, Michael wrote:
> Well I'm pretty sure the code was working just fine earlier in the week at the office, but running the code at home with the newest version of DMD started producing these odd results.

Typing this function into asm.dlang.org shows a minor difference in the assembly generated:

auto f1(double d1)
{
  d1 *= -1.0;
  return d1;
}

With DMD 2.070.2:
pure nothrow @nogc @safe double example.f1(double):
 push   %rbp
 mov    %rsp,%rbp
 sub    $0x10,%rsp
 movsd  %xmm0,-0x8(%rbp)
 xorb   $0x80,-0x1(%rbp)
 rex.W movsd  -0x8(%rbp),%xmm0
 leaveq
 retq
 nopl   0x0(%rax)

With DMD 2.071.0:
pure nothrow @nogc @safe double example.f1(double):
 push   %rbp
 mov    %rsp,%rbp
 sub    $0x10,%rsp
 movsd  %xmm0,-0x8(%rbp)
 xorb   $0x80,-0x8(%rbp)
 rex.W movsd  -0x8(%rbp),%xmm0
 leaveq
 retq
 nopl   0x0(%rax)

The xorb line is different and I conjecture that it is causing the bug. I have never used floating-point assembly instructions, so I cannot understand what the logic is here. I'll read up and try to interpret to confirm.

Hope this helps.
May 15, 2016
On Sunday, 15 May 2016 at 13:01:45 UTC, Michael wrote:
> It may be that I'm doing something wrong here, but after updating DMD to the latest version, my simulations started producing some very odd results and I think I've pinpointed it to a sign inversion that I was making. Here is some code from dpaste to demonstrate the behaviour I get vs. the behaviour I expected:
> https://dpaste.dzfl.pl/9bd7aea75fb2
>
> Any ideas? Am I getting something wrong or is this some sort of regression with the latest DMD?

It's a regression introduced here:
https://github.com/dlang/dmd/pull/5534

I've filed a bug report:
https://issues.dlang.org/show_bug.cgi?id=16027
May 15, 2016
On Sunday, 15 May 2016 at 14:12:47 UTC, Marc Schütz wrote:
> On Sunday, 15 May 2016 at 13:01:45 UTC, Michael wrote:
>> It may be that I'm doing something wrong here, but after updating DMD to the latest version, my simulations started producing some very odd results and I think I've pinpointed it to a sign inversion that I was making. Here is some code from dpaste to demonstrate the behaviour I get vs. the behaviour I expected:
>> https://dpaste.dzfl.pl/9bd7aea75fb2
>>
>> Any ideas? Am I getting something wrong or is this some sort of regression with the latest DMD?
>
> It's a regression introduced here:
> https://github.com/dlang/dmd/pull/5534
>
> I've filed a bug report:
> https://issues.dlang.org/show_bug.cgi?id=16027

Thanks for filing the bug report, and good find with the regression.