www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Complex and -O bug

reply Nick <Nick_member pathlink.com> writes:
Compiling the following with and without -O gives different results (using 0.125
on linux)

:import std.stdio;
:
:void main()
:{
:  static cdouble[] params = [1,3,5];
:
:  cdouble[] sums = new cdouble[3];
:  sums[] = 0;
:
:  foreach(cdouble d; params)
:    {
:      cdouble prod = d;
:      for(int i; i<2; i++)
:	{
:	  sums[i] += prod;
:	  prod *= d;
:	}
:      sums[2] += prod;
:    }
:  writefln(sums[0], " ", sums[1], " ", sums[2]);
:}

$ dmd run.d && run
9+0i 35+0i 153+0i (correct)

$ dmd -O run.d && run
9.0i 0+0i 0+0i (incorrect)

Nick
May 25 2005
parent Thomas Kuehne <thomas-dloop kuehne.this-is.spam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nick schrieb am Wed, 25 May 2005 18:14:47 +0000 (UTC):
 Compiling the following with and without -O gives different results (using
0.125
 on linux)

:import std.stdio;
:
:void main()
:{
:  static cdouble[] params = [1,3,5];
:
:  cdouble[] sums = new cdouble[3];
:  sums[] = 0;
:
:  foreach(cdouble d; params)
:    {
:      cdouble prod = d;
:      for(int i; i<2; i++)
:	{
:	  sums[i] += prod;
:	  prod *= d;
:	}
:      sums[2] += prod;
:    }
:  writefln(sums[0], " ", sums[1], " ", sums[2]);
:}

 $ dmd run.d && run
 9+0i 35+0i 153+0i (correct)

 $ dmd -O run.d && run
 9.0i 0+0i 0+0i (incorrect)

 Nick

Added to DStress as http://dstress.kuehne.cn/run/c/cdouble_01_A.d http://dstress.kuehne.cn/run/c/cdouble_01_B.d http://dstress.kuehne.cn/run/c/cfloat_02_A.d http://dstress.kuehne.cn/run/c/cfloat_02_B.d http://dstress.kuehne.cn/run/c/creal_26_A.d http://dstress.kuehne.cn/run/c/creal_26_B.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCnc6D3w+/yD4P9tIRAqvTAJ9VSpmpRLDRCp8wnJDfzW2aG2NnagCgs7E6 IF4LLFkJ0I7yQOw3kHDQYCM= =sRM0 -----END PGP SIGNATURE-----
Jun 01 2005