In my code have been using fragments such as the following:
uint64 ret; //return ret % iRange[config.maxLen]; return ret - (ret / iRange[config.maxLen]) * iRange[config.maxLen];
Where uint64 is an unsigned 64 bit long int. It seems as though when I use the modulo operator I sometimes get erratic results. For example, if a % b = c, I will sometimes get c which is larger than b, something I know to be impossible. The second line in the code fragment above does work as a modulo operation and in theory should give the same result. I do not believe I have been dealing with numbers which could be interpreted as negative.
a = 0x0000000171b7a70c b = 0x1a a % b = 0x00000001d1b7a726
When I manually put in constants (the numbers above) into my code, It produces the correct results. However, I think this may be due to the compiler calculating the results before runtime.
Could anyone verify this?