Thread overview | |||||
---|---|---|---|---|---|
|
May 02, 2014 why arithmetic for bytes different than for ints? | ||||
---|---|---|---|---|
| ||||
Can anyone explain to me why this test passes? I have read through the Types page on the dlang website and can't find anything that would explain this. Is it a bug or am I doing it wrong? uint x = 0; (x += 1) %= 2; assert (x == 1); ubyte y = 0; (y += 1) %= 2; assert (y != 1); // though I expected y == 1 Here's a table of all the types I tried ++x %= 2, where x has type long (L), int (I), etc: L I S B uL uI uS uB 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 It all seems very odd. |
May 02, 2014 Re: why arithmetic for bytes different than for ints? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vlad Levenfeld | Dunno why I didn't try it earlier, but splitting it across lines like y += 1; y %= 2; assert (y == 1); works. So, bug, then? |
May 02, 2014 Re: why arithmetic for bytes different than for ints? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vlad Levenfeld | On Fri, 02 May 2014 16:32:54 -0400, Vlad Levenfeld <vlevenfeld@gmail.com> wrote:
> Dunno why I didn't try it earlier, but splitting it across lines like
>
> y += 1;
> y %= 2;
> assert (y == 1);
>
> works. So, bug, then?
Yes.
-Steve
|
Copyright © 1999-2021 by the D Language Foundation