def repl_op_arithmetic(self, op, opname, x, y, i, opfunc=None):
        
        jsop = op
        if opfunc is None:
            opnumber = "x_v %s y_v" % op
        elif opfunc == 'Math.floor':
            jsop = '/'
            opnumber = "%s(x_v %s y_v)" % (opfunc, jsop)
        elif opfunc == 'mod':
            opnumber = "x_v %s y_v" % op
            opnumber = "(x_v=x_v %s y_v) < 0 && y_v > 0 ? x_v + y_v : x_v" % op
        else:
            opnumber = "%s(x_v, y_v)" % opfunc
        if op in ['/', '//', '%']:
            zerodiv = "if (${y}.valueOf() == 0) return @{{raise}}($new(@{{ZeroDivisionError}}, B$str('float divmod()')));\n";
        else:
            zerodiv = ''
        return self.substitute("""\
%(zerodiv)sif (${x} !== null && ${y} !== null) {
    var m = ${i} === true ? '__i%(opname)s__' : '__%(opname)s__';
    switch ((${x}.__number__ << 8) | ${y}.__number__) {
        case 0x0101:
        case 0x0102:
        case 0x0201:
        case 0x0104:
        case 0x0401:
            var x_v = ${x}.valueOf(), y_v = ${y}.valueOf();
            return $new(@{{float}}, %(opnumber)s);
        case 0x0202:
            return @{{int}}['$dict'].__%(opname)s__(${x}, ${y});
        case 0x0204:
            return @{{long}}['$dict'].__%(opname)s($new(@{{long}}, ${x}.__v), ${y});
        case 0x0402:
            return @{{long}}['$dict'].__%(opname)s(${x}, $new(@{{long}}, ${y}.__v));
        case 0x0404:
            return @{{long}}['$dict'].__%(opname)s(${x}, ${y});
    }
    if (${x}['$inst'] === true && ${y}['$inst'] === true) {
        var op, v;
        op = @{{_getattr}}(${x}, m);
        if (typeof op != "undefined") {
            v = @{{fcall}}(this, null, op, ${x}, ${y});
            if (v !== @{{NotImplemented}}) {
                return v;
            }
        }
        if (${i} !== true) {
            op = @{{_getattr}}(${y}, '__r%(opname)s__');
            if (typeof op != "undefined") {
                v = @{{mcall}}(this, null, ${y}, '__r%(opname)s__', ${x});
                if (v !== @{{NotImplemented}}) {
                    return v;
                }
            }
        } else {
            op = @{{_getattr}}(${x}, '__%(opname)s__');
            if (typeof op != "undefined") {
                v = @{{fcall}}(this, null, op, ${x}, ${y});
                if (v !== @{{NotImplemented}}) {
                    return v;
                }
            }
        }
    }
    var x_v = ${x}.valueOf(), y_v = ${y}.valueOf();
    if (typeof x_v == 'number' && typeof y_v == 'number') {
        return $new(@{{float}}, %(opnumber)s);
    }
}
@{{raise}}($new(@{{TypeError}}, B$str("unsupported operand type(s) for %(op)s: '" + @{{repr}}(${x}) + "', '" + @{{repr}}(${y}) + "'")));\
""" % locals(), locals())
dataset/ETHPy150Open anandology/pyjamas/pyjs/src/pyjs/builtin/mkbuiltin.py/Replacement.repl_op_arithmetic/original