Last active
January 31, 2022 22:37
-
-
Save queviva/b3016da66955682c76a19930e4431d5e to your computer and use it in GitHub Desktop.
returns a value of x, cyclically-modulated by M
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const xModByM = (x, M) => ((x % M) + M) % M; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
returns the ACTUAL modulus value of a number; that is to say, instead of negative numbers returning reverse-mod-negative values - as
happens with %= or any other modulus use - it converts the ENTIRE number-line into a cyclical universe of values from 0 - M
if you are at, say, the x-coordinate 3px, and you want to move_negative_ twenty pixels through a cyclical universe that is a hundred pixels
wide, compare these two results: