Thread overview
[Issue 326] New: calculation bug
Sep 06, 2006
d-bugmail
Sep 06, 2006
d-bugmail
Sep 07, 2006
Thomas Kuehne
Sep 19, 2006
d-bugmail
September 06, 2006
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);
}
}


-- 

September 06, 2006
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.


-- 

September 07, 2006
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


September 19, 2006
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.


--