function modularMultiply(val, factor, modulus) {
    if (val >= modulus) {
        return val;
    }
    factor = Util.properMod(factor, modulus);
    if (factor === 0 || Util.extended_gcd(factor, modulus).gcd !== 1) {
        return val;
    }
    return (val * factor) % modulus;
}
Multiplies the value by the given factor, modulo the given modulus, but with tweaks to avoid irreversible actions.

If the value is out of range or the factor is not invertible, nothing happens.

@param {!int} val
@param {!int} factor
@param {!int} modulus
@returns {!int}