Ejemplo n.º 1
0
def round_(context, node, number, ndigits):
    is_math = mathmodule.is_math_function(node.args, round)
    argtype = get_type(number)

    if len(node.args) == 1 and argtype.is_int:
        # round(myint) -> float(myint)
        return nodes.CoercionNode(node.args[0], double)

    if (argtype.is_float or argtype.is_int) and is_math:
        dst_type = argtype
    else:
        dst_type = object_
        node.args[0] = nodes.CoercionNode(node.args[0], object_)

    node.variable = Variable(dst_type)
    return nodes.CoercionNode(node, double)
Ejemplo n.º 2
0
def abs_(context, node, x):
    # Result type of the substitution during late
    # specialization
    result_type = object_
    argtype = get_type(x)

    # What we actually get back regardless of implementation,
    # e.g. abs(complex) goes throught the object layer, but we know the result
    # will be a double
    dst_type = argtype

    is_math = mathmodule.is_math_function(node.args, abs)

    if argtype.is_complex:
        dst_type = double
    elif is_math and (argtype.is_float or argtype.is_int):
        result_type = argtype

    node.variable = Variable(result_type)
    return nodes.CoercionNode(node, dst_type)