Compiler bug? Addition/subtraction code
Era Scarecrow via D.gnu
d.gnu at puremagic.com
Mon Jun 19 18:58:22 PDT 2017
Passes in DMD compiler, but breaks in GDC during assert tests.
B4S1L3 suggested it might be an old compiler bug. I need
confirmation if this is an old (not yet caught up) or a new one
(to which I'll have to write or have a work-around until the bug
is fixed).
// http://dpaste.com/0M7M8NK
uint[] sub(uint[] lhs, const (uint)[] rhs) {
long t; //temporary, doubles as carry
foreach(i, ref v; lhs) {
t += v;
t -= rhs[i];
v = cast(uint) t;
//reset carry
t >>= uint.sizeof*8;
}
return lhs;
}
unittest {
uint[3] lhs = [99, 201, 300],
rhs = [-1, 0, 0];
assert(sub(lhs, rhs) == [100, 200, 300]);
}
More information about the D.gnu
mailing list