Status: Accepted
Owner: asmeurer
Labels: Type-Defect Priority-Medium
New issue 1834 by asmeurer: x&y code generation should not produce And(x, y)
http://code.google.com/p/sympy/issues/detail?id=1834
From
http://groups.google.com/group/sympy/browse_thread/thread/d79d7a74b12429aa
"""
Hi all,
I just found a bug in code generation with Boolean operators. For
example, the sympy expression x&y ought to generate the C++ code x&&y
but it actually generates And(x,y). I have a fix for this to add to
sympy.printing.ccode.CCodePrinter, the extra methods:
def _print_And(self, expr):
PREC = precedence(expr)
return '&&'.join(self.parenthesize(a, PREC) for a in
expr.args)
def _print_Or(self, expr):
PREC = precedence(expr)
return '||'.join(self.parenthesize(a, PREC) for a in
expr.args)
def _print_Not(self, expr):
PREC = precedence(expr)
return '!'+self.parenthesize(expr.args[0], PREC)
I don't mess around with sympy internals much, so I might be using
self.parenthesize and precedence wrong here (it certainly seems to
create too many parentheses like this), but it does at least seem to
work.
Dan Goodman
"""
Apparently, this creates more parentheses than necessary, and tests (not to
mention making this
into an actual patch) need to be written too.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--
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.