'Optimise math operators for (likely) float or small integer operations.'

def _optimise_num_binop(self, operator, node, function, args, is_unbound_method):

    if (len(args) != 2):
        return node
    if (not node.type.is_pyobject):
        return node
    num_nodes = (ExprNodes.IntNode, ExprNodes.FloatNode)
    if isinstance(args[1], num_nodes):
        if (args[0].type is not PyrexTypes.py_object_type):
            return node
        numval = args[1]
        arg_order = 'ObjC'
    elif isinstance(args[0], num_nodes):
        if (args[1].type is not PyrexTypes.py_object_type):
            return node
        numval = args[0]
        arg_order = 'CObj'
    else:
        return node
    if (not numval.has_constant_result()):
        return node
    is_float = isinstance(numval, ExprNodes.FloatNode)
    if is_float:
        if (operator not in ('Add', 'Subtract', 'Remainder', 'TrueDivide', 'Divide', 'Eq', 'Ne')):
            return node
    elif (operator == 'Divide'):
        return node
    elif (abs(numval.constant_result) > (2 ** 30)):
        return node
    args = list(args)
    args.append((ExprNodes.FloatNode if is_float else ExprNodes.IntNode)(numval.pos, value=numval.value, constant_result=numval.constant_result, type=(PyrexTypes.c_double_type if is_float else PyrexTypes.c_long_type)))
    inplace = (node.inplace if isinstance(node, ExprNodes.NumBinopNode) else False)
    args.append(ExprNodes.BoolNode(node.pos, value=inplace, constant_result=inplace))
    utility_code = TempitaUtilityCode.load_cached(('PyFloatBinop' if is_float else 'PyIntBinop'), 'Optimize.c', context=dict(op=operator, order=arg_order))
    return self._substitute_method_call(node, function, ('__Pyx_Py%s_%s%s' % (('Float' if is_float else 'Int'), operator, arg_order)), (self.Pyx_PyFloat_BinopInt_func_type if is_float else self.Pyx_PyInt_BinopInt_func_type), ('__%s__' % operator[:3].lower()), is_unbound_method, args, may_return_none=True, with_none_check=False, utility_code=utility_code)
