From b7a64234d0faba56fbedb76010e06670e2d53a00 Mon Sep 17 00:00:00 2001
From: Frederik Hennig <frederik.hennig@fau.de>
Date: Tue, 2 Jul 2024 15:51:45 +0200
Subject: [PATCH] Symboloc C-style integer remainder

---
 src/pystencils/backend/kernelcreation/freeze.py     |  3 +++
 src/pystencils/sympyextensions/integer_functions.py | 11 ++++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/pystencils/backend/kernelcreation/freeze.py b/src/pystencils/backend/kernelcreation/freeze.py
index 35076f205..a73c23279 100644
--- a/src/pystencils/backend/kernelcreation/freeze.py
+++ b/src/pystencils/backend/kernelcreation/freeze.py
@@ -33,6 +33,7 @@ from ..ast.expressions import (
     PsCast,
     PsConstantExpr,
     PsIntDiv,
+    PsRem,
     PsLeftShift,
     PsLookup,
     PsRightShift,
@@ -391,6 +392,8 @@ class FreezeExpressions:
                 return PsCall(PsMathFunction(MathFunctions.ATan2), args)
             case integer_functions.int_div():
                 return PsIntDiv(*args)
+            case integer_functions.int_rem():
+                return PsRem(*args)
             case integer_functions.bit_shift_left():
                 return PsLeftShift(*args)
             case integer_functions.bit_shift_right():
diff --git a/src/pystencils/sympyextensions/integer_functions.py b/src/pystencils/sympyextensions/integer_functions.py
index c3dd18108..2f48b42b2 100644
--- a/src/pystencils/sympyextensions/integer_functions.py
+++ b/src/pystencils/sympyextensions/integer_functions.py
@@ -45,9 +45,18 @@ class bitwise_or(IntegerFunctionTwoArgsMixIn):
 
 # noinspection PyPep8Naming
 class int_div(IntegerFunctionTwoArgsMixIn):
+    """C-style integer division,"""
     
     def _eval_op(self, arg1, arg2):
-        return int(arg1 // arg2)
+        return int(arg1 / arg2)
+
+
+class int_rem(IntegerFunctionTwoArgsMixIn):
+    """C-style integer remainder"""
+    
+    def _eval_op(self, arg1, arg2):
+        div = int(arg1 / arg2)
+        return arg1 - div * arg2
 
 
 # noinspection PyPep8Naming
-- 
GitLab