Commit 2178b66e authored by Markus Holzer's avatar Markus Holzer
Browse files

Use Walrus operator

parent a27c182a
Pipeline #36486 failed with stages
in 3 minutes and 27 seconds
......@@ -453,10 +453,8 @@ class CustomSympyPrinter(CCodePrinter):
def _print_Rational(self, expr):
"""Evaluate all rationals i.e. print 0.25 instead of 1.0/4.0"""
res = str(expr.evalf(17))
if "." in res:
res = res.rstrip('0')
if res[-1] == ".":
res += '0'
if p := res.find('.'):
res = res[:p + 2] + res[p + 2:].rstrip('0')
return res
def _print_Equality(self, expr):
......@@ -529,10 +527,8 @@ class CustomSympyPrinter(CCodePrinter):
def _typed_number(self, number, dtype):
res = self._print(number)
if "." in res:
res = res.rstrip('0')
if res[-1] == ".":
res += '0'
if p := res.find('.'):
res = res[:p + 2] + res[p + 2:].rstrip('0')
if dtype.numpy_dtype == np.float32:
return res + '.0f' if '.' not in res else res + 'f'
elif dtype.numpy_dtype == np.float64:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment