From 37650bc9147e7fc52f670bd14bee8a3aa161fd41 Mon Sep 17 00:00:00 2001
From: Nils Kohl <nils.kohl@fau.de>
Date: Wed, 12 Jun 2019 18:44:49 +0200
Subject: [PATCH] Added new sympy integer function: integer modulo, extended
 cbackend

---
 pystencils/backends/cbackend.py | 4 +++-
 pystencils/integer_functions.py | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/pystencils/backends/cbackend.py b/pystencils/backends/cbackend.py
index 18fd1d344..cd71d0ffb 100644
--- a/pystencils/backends/cbackend.py
+++ b/pystencils/backends/cbackend.py
@@ -13,7 +13,7 @@ except ImportError:
     from sympy.printing.ccode import CCodePrinter  # for sympy versions < 1.1
 
 from pystencils.integer_functions import bitwise_xor, bit_shift_right, bit_shift_left, bitwise_and, \
-    bitwise_or, modulo_ceil, int_div, int_power_of_2
+    bitwise_or, modulo_ceil, int_div, int_power_of_2, int_mod
 from pystencils.astnodes import Node, KernelFunction
 from pystencils.data_types import create_type, PointerType, get_type_of_expression, VectorType, cast_func, \
     vector_memory_access, reinterpret_cast_func
@@ -308,6 +308,8 @@ class CustomSympyPrinter(CCodePrinter):
             return "(1 << (%s))" % (self._print(expr.args[0]))
         elif expr.func == int_div:
             return "((%s) / (%s))" % (self._print(expr.args[0]), self._print(expr.args[1]))
+        elif expr.func == int_mod:
+            return "((%s) %% (%s))" % (self._print(expr.args[0]), self._print(expr.args[1]))
         else:
             return super(CustomSympyPrinter, self)._print_Function(expr)
 
diff --git a/pystencils/integer_functions.py b/pystencils/integer_functions.py
index 2fbc1ed67..5b243622e 100644
--- a/pystencils/integer_functions.py
+++ b/pystencils/integer_functions.py
@@ -10,6 +10,7 @@ bitwise_and = sp.Function("bitwise_and")
 bitwise_or = sp.Function("bitwise_or")
 int_div = sp.Function("int_div")
 int_power_of_2 = sp.Function("int_power_of_2")
+int_mod = sp.Function("int_mod")
 
 
 # noinspection PyPep8Naming
-- 
GitLab