Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
August 24, 2005 mistake in the calculation when compiling | ||||
---|---|---|---|---|
| ||||
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 } |
August 24, 2005 Re: mistake in the calculation when compiling | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hiroshi Sakurai | 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.
|
August 24, 2005 Re: mistake in the calculation when compiling | ||||
---|---|---|---|---|
| ||||
Posted in reply to zwang | 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 |
August 27, 2005 Re: mistake in the calculation when compiling | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | >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.
|
August 27, 2005 Re: mistake in the calculation when compiling | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hiroshi Sakurai Attachments: | 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 |
Copyright © 1999-2021 by the D Language Foundation