www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - mistake in the calculation when compiling

reply Hiroshi Sakurai <Hiroshi_member pathlink.com> writes:
Hi.
This topic writen U in Japanese D Language Wiki.
http://f17.aaa.livedoor.jp/~labamba/?BugTrack%2F19

foo(-288*1000/360) is not -800.



void main(char[][] arg) {
printf("ok %d\n",  3/3);// 1
printf("ok %d\n", -(3/3));// -1

printf("ng %d\n", -3/3);// 1431655764
int a = cast(int)(-3/3);
printf("ng %d\n", a);// 1431655764
printf("ng %d\n", (-3)/3);// 1431655764
}
Aug 24 2005
next sibling parent reply zwang <nehzgnaw gmail.com> writes:
Hiroshi Sakurai wrote:
 Hi.
 This topic writen U in Japanese D Language Wiki.
 http://f17.aaa.livedoor.jp/~labamba/?BugTrack%2F19
 
 foo(-288*1000/360) is not -800.
 
 
 
 void main(char[][] arg) {
 printf("ok %d\n",  3/3);// 1
 printf("ok %d\n", -(3/3));// -1
 
 printf("ng %d\n", -3/3);// 1431655764
 int a = cast(int)(-3/3);
 printf("ng %d\n", a);// 1431655764
 printf("ng %d\n", (-3)/3);// 1431655764
 }
 
 
Already reported. See D.bugs:4750.
Aug 24 2005
parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
zwang wrote:
 Hiroshi Sakurai wrote:
 
 Hi.
 This topic writen U in Japanese D Language Wiki.
 http://f17.aaa.livedoor.jp/~labamba/?BugTrack%2F19

 foo(-288*1000/360) is not -800.



 void main(char[][] arg) {
 printf("ok %d\n",  3/3);// 1
 printf("ok %d\n", -(3/3));// -1

 printf("ng %d\n", -3/3);// 1431655764
 int a = cast(int)(-3/3);
 printf("ng %d\n", a);// 1431655764
 printf("ng %d\n", (-3)/3);// 1431655764
 }
Already reported. See D.bugs:4750.
but this is kind of different, it's not treated as positive (or atleast doesn't seem like that) funny thing is, -2/2 works fine!! and so does -3/1 it's kind of odd .. in some cases it works, some cases it doesn't .. maybe an optamization bug? <bug.d> void main(char[][] arg) { printf("-5/3 prints: %d\n", -5/3); printf("-5/2 prints: %d\n", -5/2); printf("-7/3 prints: %d\n", -7/3); printf("-7/4 prints: %d\n", -7/4); printf("-7/7 prints: %d\n", -7/7); printf("-8/7 prints: %d\n", -8/7); printf("-9/7 prints: %d\n", -9/7); printf("-11/8 prints: %d\n", -11/8); printf("-7/9 prints: %d\n", -7/9); } </bug.d> output: D:\Documents and Settings\Aljudy\temp>dmd bug E:\dmd\dmd\bin\..\..\dm\bin\link.exe bug,,,user32+kernel32/noi; D:\Documents and Settings\Aljudy\temp>bug -5/3 prints: 1431655763 -5/2 prints: -3 -7/3 prints: 1431655763 -7/4 prints: -2 -7/7 prints: -1840700271 -8/7 prints: -1840700271 -9/7 prints: -1840700271 -11/8 prints: -2 -7/9 prints: 1908874353
Aug 24 2005
parent Hiroshi Sakurai <Hiroshi_member pathlink.com> writes:
zwang wrote:
 Hiroshi Sakurai wrote:
 
 Hi.
 This topic writen U in Japanese D Language Wiki.
 http://f17.aaa.livedoor.jp/~labamba/?BugTrack%2F19

 foo(-288*1000/360) is not -800.



 void main(char[][] arg) {
 printf("ok %d\n",  3/3);// 1
 printf("ok %d\n", -(3/3));// -1

 printf("ng %d\n", -3/3);// 1431655764
 int a = cast(int)(-3/3);
 printf("ng %d\n", a);// 1431655764
 printf("ng %d\n", (-3)/3);// 1431655764
 }
Already reported. See D.bugs:4750.
but this is kind of different, it's not treated as positive (or atleast doesn't seem like that) funny thing is, -2/2 works fine!! and so does -3/1 it's kind of odd .. in some cases it works, some cases it doesn't .. maybe an optamization bug? <bug.d> void main(char[][] arg) { printf("-5/3 prints: %d\n", -5/3); printf("-5/2 prints: %d\n", -5/2); printf("-7/3 prints: %d\n", -7/3); printf("-7/4 prints: %d\n", -7/4); printf("-7/7 prints: %d\n", -7/7); printf("-8/7 prints: %d\n", -8/7); printf("-9/7 prints: %d\n", -9/7); printf("-11/8 prints: %d\n", -11/8); printf("-7/9 prints: %d\n", -7/9); } </bug.d> output: D:\Documents and Settings\Aljudy\temp>dmd bug E:\dmd\dmd\bin\..\..\dm\bin\link.exe bug,,,user32+kernel32/noi; D:\Documents and Settings\Aljudy\temp>bug -5/3 prints: 1431655763 -5/2 prints: -3 -7/3 prints: 1431655763 -7/4 prints: -2 -7/7 prints: -1840700271 -8/7 prints: -1840700271 -9/7 prints: -1840700271 -11/8 prints: -2 -7/9 prints: 1908874353
Thank you for having already taught what the bug has reported. I am not reading all Newsgroups. Therefore, I did not notice it. I thought that it was interesting that -2/2 had moved well. I also thought that it might have happened while the bug had optimized the code. Hiroshi Sakurai.
Aug 27 2005
prev sibling parent =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hiroshi Sakurai schrieb:

 Hi.
 This topic writen U in Japanese D Language Wiki.
 http://f17.aaa.livedoor.jp/~labamba/?BugTrack%2F19
 
 foo(-288*1000/360) is not -800.
 
 
 
 void main(char[][] arg) {
 printf("ok %d\n",  3/3);// 1
 printf("ok %d\n", -(3/3));// -1
 
 printf("ng %d\n", -3/3);// 1431655764
 int a = cast(int)(-3/3);
 printf("ng %d\n", a);// 1431655764
 printf("ng %d\n", (-3)/3);// 1431655764
 }
Added to DStress as http://dstress.kuehne.cn/run/o/opDiv_10_A.d http://dstress.kuehne.cn/run/o/opDiv_10_B.d Thomas -----BEGIN PGP SIGNATURE----- iD4DBQFDEJss3w+/yD4P9tIRAiTUAJi0XU4grbgT6BRLeg7ew3+WVTviAKCWEyBI 1G6VcZpxQGO4+qnUN0s3Og== =MlOX -----END PGP SIGNATURE-----
Aug 27 2005