(pyexpr)
return pyexpr
Python math expression string -> C expression string
Python math expression string -> C expression string
Python math expression string - > C expression string
def cexpr(pyexpr):
    """
    Python math expression string -> C expression string
    """
    # TODO: better spacing
    # replace 'a**b' with 'pow(a, b)'
    while True:
        index = pyexpr.find('**')
        if index != -1:
            left, right = __getLeftRight(pyexpr, index, 2, '+-*/')
            pyexpr = pyexpr.replace(left + '**' + right, ' pow(%s, %s) '
                                    % (left.lstrip(), right.rstrip()))
        else:
            break
    # TODO: convert 'x**n' to 'x*x*...*x'
    # TODO: avoid integer division
    return pyexpr
def cexpr ( pyexpr ) : # TODO: better spacing # replace 'a**b' with 'pow(a, b)' while True : index = pyexpr . find ( '**' ) if index != - 1 : left , right = __getLeftRight ( pyexpr , index , 2 , '+-*/' ) pyexpr = pyexpr . replace ( left + '**' + right , ' pow(%s, %s) ' % ( left . lstrip ( ) , right . rstrip ( ) ) ) else : break # TODO: convert 'x**n' to 'x*x*...*x' # TODO: avoid integer division return pyexpr