diff --git a/pystencils/backends/cbackend.py b/pystencils/backends/cbackend.py index 239f060eee7de833321f811ed95b05ff8f02adbb..4e7c5cf2445c07f79dddc2c7eba93c520e2b320c 100644 --- a/pystencils/backends/cbackend.py +++ b/pystencils/backends/cbackend.py @@ -380,6 +380,10 @@ class CustomSympyPrinter(CCodePrinter): return res + '.0f' if '.' not in res else res + 'f' elif dtype.numpy_dtype == np.float64: return res + '.0' if '.' not in res else res + elif dtype.numpy_dtype == np.complex64: + return f"{_typed_number(number.real, np.float32)} + {_typed_number(number.real, np.float32).replace('f', 'if')}" + elif dtype.numpy_dtype == np.complex128: + return f"{_typed_number(number.real, np.float64)} + {_typed_number(number.real, np.float64)}i" else: return res @@ -431,6 +435,15 @@ class CustomSympyPrinter(CCodePrinter): _print_Max = C89CodePrinter._print_Max _print_Min = C89CodePrinter._print_Min + def _print_re(self, expr): + return f"std::real({self._print(expr.args[0])})" + + def _print_im(self, expr): + return f"std::imag({self._print(expr.args[0])})" + + def _print_ImaginaryUnit(self, expr): + return "1if" + # noinspection PyPep8Naming class VectorizedCustomSympyPrinter(CustomSympyPrinter):