diff --git a/src/pystencils/backend/kernelcreation/freeze.py b/src/pystencils/backend/kernelcreation/freeze.py index 35076f205a93b9a50ea9295024a6b6f52e78f46c..a73c232791c3029870e4e3b523746883c8f5515c 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 c3dd181083ecbfecf5dc6d445f5fa1d0ac45f601..2f48b42b29627c464a55557e1eec8c5c87a8155a 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