PyGLM icon indicating copy to clipboard operation
PyGLM copied to clipboard

Modulo operator does not conform to standard Python behavior

Open avdstaaij opened this issue 1 year ago • 3 comments

In Python, the result of a % b for integers a and b always has the same sign as b. Numpy follows this convention as well. PyGLM, however, does not follow this rule for integer vectors. On my machine:

>>> -3 % 2
1

>>> np.array([-3]) % 2
array([1])

>>> vec2(-3,-3) % 2
vec2(1,1)

>>> ivec2(-3,-3) % 2
ivec2(-1,-1)

I assume the sign is unspecified for pyGLM in the last case.

I've looked in GLM's documentation of the modulo function. While it states that floating point modulo should behave like it does in Python, it does not actually describe an integer modulo operation at all, so it seems like pyGLM is free to choose what to do here.

I would like to request integer modulo to behave in the standard Python way (the same way as floating point modulo). This would reduce confusion and prevent subtle bugs.

avdstaaij avatar Jan 24 '23 00:01 avdstaaij