diff --git a/src/core/checkedint.d b/src/core/checkedint.d index b474e141ce..99096fa1c4 100644 --- a/src/core/checkedint.d +++ b/src/core/checkedint.d @@ -168,9 +168,7 @@ pragma(inline, true) uint addu()(uint x, uint y, ref bool overflow) { immutable uint r = x + y; - immutable bool o = r < x; - assert(o == (r < y)); - if (o) + if (r < x || r < y) overflow = true; return r; } @@ -179,14 +177,6 @@ uint addu()(uint x, uint y, ref bool overflow) @betterC unittest { - for (uint i = 0; i < 10; ++i) - { - bool overflow; - immutable uint r = addu (uint.max - i, uint.max - i, overflow); - assert (r == 2 * (uint.max - i)); - assert (overflow); - } - bool overflow; assert(addu(2, 3, overflow) == 5); assert(!overflow); @@ -213,9 +203,7 @@ pragma(inline, true) ulong addu()(ulong x, ulong y, ref bool overflow) { immutable ulong r = x + y; - immutable bool o = r < x; - assert(o == (r < y)); - if (o) + if (r < x || r < y) overflow = true; return r; } @@ -252,9 +240,7 @@ pragma(inline, true) ucent addu()(ucent x, ucent y, ref bool overflow) { immutable ucent r = x + y; - immutable bool o = r < x; - assert(o == (r < y)); - if (o) + if (r < x || r < y) overflow = true; return r; }