function floorMod(a, n) {
        var f = a - n * Math.floor(a / n);
        // HACK: when a is extremely close to an n transition, f can be equal to n. This is bad because f must be
        //       within range [0, n). Check for this corner case. Example: a:=-1e-16, n:=10. What is the proper fix?
        return f === n ? 0 : f;
    }
@returns {Number} returns remainder of floored division, i.e., floor(a / n). Useful for consistent modulo
         of negative numbers. See http://en.wikipedia.org/wiki/Modulo_operation.