GridTools / gt4py

Python library for generating high-performance implementations of stencil kernels for weather and climate modeling from a domain-specific language (DSL).
https://GridTools.github.io/gt4py
Other
106 stars 48 forks source link

Modulo: Python vs C++ #1219

Open havogt opened 1 year ago

havogt commented 1 year ago

-1 % 2 == -1 in C++, but -1 % 2 == 1 in Python.

In gt4py.next we get different result for C++ and Python backends.

egparedes commented 1 year ago

Just for information, math.fmod() implements the same behavior as C/C++ and according to the documentation (https://devdocs.io/python~3.11/library/math#math.fmod) is preferred when working with floats, but the default implementation of operator.__mod__() in python works differently, so it's not so clear to me how to proceed for the embedded backends.