www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 326] New: calculation bug

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=326

           Summary: calculation bug
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: sugiyama563 msn.com


To compile this code with '-release -O' brings a incorrect calculation.

import std.stdio;

int x = 2, y = 1;

void main() {
int res = 0;
for(int i = 0; i < 10; i++) {
res = res + x - y;
writefln(res);
}
}


-- 
Sep 06 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=326





------- Comment #1 from jpelcis gmail.com  2006-09-06 17:46 -------
-release isn't required.  Only -O is needed for the bug.

This error also occurs in DMC with similar code.

The error will disappear if x is of any other type except uint, y is a long or
ulong, or res is a byte, ubyte, long, or ulong.  Casting to those types also
gets rid of the bug.

I hope that helps.


-- 
Sep 06 2006
prev sibling next sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail puremagic.com schrieb am 2006-09-06:
 http://d.puremagic.com/issues/show_bug.cgi?id=326

 To compile this code with '-release -O' brings a incorrect calculation.

 import std.stdio;

 int x = 2, y = 1;

 void main() {
 int res = 0;
 for(int i = 0; i < 10; i++) {
 res = res + x - y;
 writefln(res);
 }
 }

Added to DStress as http://dstress.kuehne.cn/run/o/odd_bug_08_A.d http://dstress.kuehne.cn/run/o/odd_bug_08_B.d http://dstress.kuehne.cn/run/o/odd_bug_08_C.d http://dstress.kuehne.cn/run/o/odd_bug_08_D.d http://dstress.kuehne.cn/run/o/odd_bug_08_E.d http://dstress.kuehne.cn/run/o/odd_bug_08_F.d http://dstress.kuehne.cn/run/o/odd_bug_08_H.d http://dstress.kuehne.cn/run/o/odd_bug_08_I.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFE/81ELK5blCcjpWoRAi9CAJ0eCrTu5PYdh2ZntTOvLxArdjFmZACfWufb ieqAan4Y85X4k3uszBIu3+g= =aL0Z -----END PGP SIGNATURE-----
Sep 07 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=326


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #3 from bugzilla digitalmars.com  2006-09-19 15:29 -------
Fixed in DMC 0.167.


-- 
Sep 19 2006