-
Notifications
You must be signed in to change notification settings - Fork 6
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
Positive modulo #4
Comments
Generally in favour of this one, and for the Wondering about the name. Reading about division, there's apparently the concept of Euclidean division which more or less matches : So I consider function names like:
We might need to accept the fact that there's no super-intuitive name that would make users go "oh, yes, it's the kind of mod/div that handles negative values properly!" and explain things in JSDoc instead. Still, other name suggestions welcome. |
I agree with this suggestion. As for name in my own code, I opted for the EDIT: My second suggestion was silly because I misread the post. A third suggestion is maybe |
|
Actually I'm fond of |
Alright, then maybe let's do some voting on the naming? Since
People seem to agree that it would be a nice addition, and it seems naming is the only remaining thing to settle before proceeding with implementation. |
Alright, those who voted agreed that When it comes to function eucdiv(_a, _b) {
return (a - eucmod(_a, _b)) div _b;
} Or at least, it matches the definition of Euclidean division. The tests should verify that:
When it comes to the demonstration, I imagine some grid-snapped input would illustrate it pretty well. If someone does start the implementation work, please tell it here to avoid other people duplicating your work and allow better coordination in general. |
I will go ahead and say that I am starting the implementation work. I will let folks know if any issues arise, or if I am unable to complete it due to schedule conflicts, etc. I'm adjusting Merc's algorithm to be correct with Euclidian division mods in the case of negative divisors. It seems to me that what he has as of now is based on floor division.
For more on Euclidian/floor division, see (Look especially at the C implementations!): You can see people doing various implementations of floor division here: Take care, folks! :) |
The related PR has been merged, and thus I'm closing this issue. |
Here's a short function that I throw in every project I ever write, pretty much. The built-in Game Maker modulo operator % takes the sign of the dividend, matching the behavior of C. This can cause awkwardness when using % to perform wrapping behavior on a value that might be negative. This is a variant of the modulo function that matches the sign of the result to the sign of the divisor.
The text was updated successfully, but these errors were encountered: