Why isn't the overflow flag set?

Simen Kjærås simen.kjaras at gmail.com
Thu Nov 10 09:24:30 PST 2011


I'm creating a Checked!T struct for integral values. The version attached  
works
for the most part, but some parts confuse me, namely that the following
operations do not set the overflow flag:

uint.max + 1
ulong.max + 1

int.min - 1
uint.min - 1
long.min - 1
ulong.min - 1

uint.max << 1
long.max << 1
ulong.max << 1

int.min << 1
long.min << 1

int a = int.max; a *= 2
long a = long.max; a *= 2

The following feel wrong to me, but I guess there may be reasons behind  
them:

ubyte a = ubyte.min; --a
ushort a = ushort.min; --a
uint a = uint.min; --a
ulong a = ulong.min; --a

ubyte a = ubyte.max; ++a
ushort a = ushort.max; ++a
uint a = uint.max; ++a
ulong a = ulong.max; ++a

ubyte a = ubyte.max; a *= 2
ushort a = ushort.max; a *= 2
uint a = uint.max; a *= 2
ulong a = ulong.max; a *= 2

ubyte a = ubyte.min; a -= 1
ushort a = ushort.min; a -= 1
uint a = uint.min; a -= 1
ulong a = ulong.min; a -= 1

ubyte a = ubyte.max; a <<= 1
ushort a = ushort.max; a <<= 1
uint a = uint.max; a <<= 1
ulong a = ulong.max; a <<= 1

Are some of these supposed to work but don't?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: checkedint.d
Type: application/octet-stream
Size: 5808 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20111110/107eb17a/attachment.obj>


More information about the Digitalmars-d-learn mailing list