Bug 326 – calculation bug

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2006-09-06T12:46:00Z
Last change time
2015-06-09T05:15:03Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
sugiyama563

Comments

Comment #0 by sugiyama563 — 2006-09-06T12:46:18Z
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); } }
Comment #1 by jpelcis — 2006-09-06T17:46:20Z
-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.
Comment #2 by thomas-dloop — 2006-09-07T03:00:27Z
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [email protected] 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-----
Comment #3 by bugzilla — 2006-09-19T15:29:08Z
Fixed in DMC 0.167.