Skip to content

Commit afba43a

Browse files
fix #7085
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
1 parent 4ff352f commit afba43a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/api/python/z3/z3printer.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ def _is_html_left_assoc(k):
252252

253253

254254
def _is_add(k):
255-
return k == Z3_OP_ADD or k == Z3_OP_BADD
255+
return k == Z3_OP_ADD or k == Z3_OP_BADD or k == Z3_OP_FPA_ADD
256256

257257

258258
def _is_sub(k):
259-
return k == Z3_OP_SUB or k == Z3_OP_BSUB
259+
return k == Z3_OP_SUB or k == Z3_OP_BSUB or k == Z3_OP_FPA_SUB
260260

261261

262262
if sys.version_info.major < 3:
@@ -890,9 +890,21 @@ def pp_fp(self, a, d, xs):
890890
if self.is_infix(k) and n >= 3:
891891
rm = a.arg(0)
892892
if z3.is_fprm_value(rm) and z3.get_default_rounding_mode(a.ctx).eq(rm):
893-
arg1 = to_format(self.pp_expr(a.arg(1), d + 1, xs))
894-
arg2 = to_format(self.pp_expr(a.arg(2), d + 1, xs))
893+
p = self.get_precedence(k)
895894
r = []
895+
x = a.arg(1)
896+
y = a.arg(2)
897+
arg1 = to_format(self.pp_expr(x, d + 1, xs))
898+
arg2 = to_format(self.pp_expr(y, d + 1, xs))
899+
if z3.is_app(x):
900+
child_k = x.decl().kind()
901+
if child_k != k and self.is_infix(child_k) and self.get_precedence(child_k) > p:
902+
arg1 = self.add_paren(arg1)
903+
if z3.is_app(y):
904+
child_k = y.decl().kind()
905+
if child_k != k and self.is_infix(child_k) and self.get_precedence(child_k) > p:
906+
arg2 = self.add_paren(arg2)
907+
896908
r.append(arg1)
897909
r.append(to_format(" "))
898910
r.append(to_format(op))

0 commit comments

Comments
 (0)