-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modulo operator does not conform to standard Python behavior #207
Comments
This is a bit of a tricky topic. In general, a mod operation and the corresponding div operation need to satisfy the following conditions:
You are correct that GLM does not define a modulo for int vectors, however, it does define a division function for int vectors. The issue here is that python defines two different div operations ( I find that it's more reasonable that Floored division and it's respective modulo also take a bit longer to compute. I believe there should at least be a method to do the floormod operation on int vectors. |
Hmm, I suppose you're right. I was aware of the different interpretations of modulo, but I hadn't considered that it should match the division function. It might have been more "Pythonic" to make integer It might be worth it to describe this edge case in the wiki, since this behavior may be unexpected to Python developers. |
Yes, you're right. A note in the documentation is the least I should do. Perhaps I should also add dedicated |
In Python, the result of
a % b
for integersa
andb
always has the same sign asb
. Numpy follows this convention as well. PyGLM, however, does not follow this rule for integer vectors. On my machine: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.
The text was updated successfully, but these errors were encountered: