Comment #1 on issue 2557 by brad.froehle: inline Piecewise C code constructs not actually valid C
http://code.google.com/p/sympy/issues/detail?id=2557

One immediate problem here is how to handle the situation where the condition for the last entry of Piecewise is not True. I suggest then using NAN to handle that case. The implementation could be as simple as


def _print_Piecewise(self, expr):
    # This method is called only for inline if constructs
    # Top level piecewise is handled in doprint()
    if expr.args[-1].cond == True:
        code = self._print(expr.args[-1].expr)
        last = -1
    else:
        code = "NAN"
        last = None
    for e,c in reversed(expr.args[:last]):
        code = "((%s) ? (%s) : (%s))" % (self._print(c), \
                                         self._print(e), code)
    return code


--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to