"Unsigned-related bugs never occur in real code."

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Jan 20 20:42:50 PST 2010


"It's an academic problem. Don't worry about it and move on."

That's what Walter kept on telling me. Yet I've spent the better part of 
an hour reducing a bug down to the following:

import std.math, std.stdio;

void main() {
     auto a = [ 4, 4, 2, 3, 2 ];
     float avgdist = 0;
     uint count;

     foreach (i, e1; a) {
         foreach (j, e2; a) {
             if (i == j) continue;
             if (e1 != e2) continue;
             ++count;
             avgdist += abs(i - j);
         }
     }

     writeln(count, " ", avgdist / count);
}

May this post be an innocent victim of the war against unsigned-related 
bugs.


Andrei



More information about the Digitalmars-d mailing list