I assumed that all the numbers are already modulo M, that is they actually fall within the existing world. There is no way it should overflow the border, otherwise your code sucks. Its like saying that you have an unsigned integer and wanting to put -1 into it. Its an error. Its is like saying that you want to have a byte and store a number bigger than 255 into it.
4 Likes