why arithmetic for bytes different than for ints?
Vlad Levenfeld via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri May 2 13:21:17 PDT 2014
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.
More information about the Digitalmars-d-learn
mailing list